Last active
July 30, 2017 15:42
-
-
Save guysmoilov/9098eba0f9d777a1ed8320d4ba165b7f to your computer and use it in GitHub Desktop.
Saves an octet-stream returned from a REST call as a file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var toSend = {}; | |
var xmlhttp = new XMLHttpRequest(); | |
xmlhttp.open("POST", "https://myserver.com/path", true); | |
xmlhttp.responseType="blob"; | |
xmlhttp.setRequestHeader("Content-Type", "application/json"); | |
xmlhttp.overrideMimeType('application/octet-stream'); | |
xmlhttp.onload = function() { | |
console.log('success'); | |
console.log(xmlhttp.response); | |
window.open(URL.createObjectURL(xmlhttp.response)).focus(); | |
}; | |
xmlhttp.send(JSON.stringify(toSend)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment