Jojo GKH
Jojo GKH

Reputation: 57

javascript Blob Object is undefined

I'm trying to download content through XHR post and save it locally, so I tried to restore recieved data into a blob object as a file but a jscript error is fired saying that blob is undefined !

window.URL = window.URL || window.webkitURL;
$.ajax({
url: 'CreateFile.aspx',
type: 'POST',
data: { 'param1': "verylargedata1",
    'param2': "verylargedata2"
},
headers: {
    "accept": 'application/octet-stream',
    "content-type": 'application/x-www-form-urlencoded',
    "X-RequestDigest": $("#__REQUESTDIGEST").val()
},
error: function (xhr, ajaxOptions, thrownError) {
    alert(xhr.status);
    alert(thrownError);
},
success: function (data) {
    var blob = new Blob(data, { 'type': "application/octet-stream" }); //Jscript error undeined blob
    var url = window.URL.createObjectURL(blob);
    iframe.src = encodeURI(url);
}
});

Upvotes: 0

Views: 4318

Answers (1)

epascarello
epascarello

Reputation: 207557

It is not supported in many browsers. I am guessing you are using IE9 or under since it says JScript in the error message. IE10 has some support.

For current browser support check out: http://caniuse.com/#search=blob

Upvotes: 2

Related Questions