Skip to content Skip to sidebar Skip to footer

Invalidstateerror In Internet Explorer 11 During Blob Creation

I'm getting an InvalidStateError at the blob creation line on IE 11. Needless to say, it works in Chrome and Firefox. I can see that the binary data is my client side. Are there a

Solution 1:

After instantiating an XmlHttpRequest with xhr.responseType = "blob" I was getting an InvalidStateError. However, moving xhr.responseType = "blob" to onloadstart solved it for me! :)

xhr.onloadstart = function(ev) {
    xhr.responseType = "blob";
}

Solution 2:

Spent some time on this and actually found out adding new Uint8Array works:

var blob = newBlob([newUint8Array(request.response)], {type: 'application/pdf'});

Solution 3:

Is not a elegant way but it works on IE8 - IE11:

var myForm = document.createElement("form");

myForm.method = "POST";
myForm.action = strURL;
myForm.target = "_blank";

var myInput = document.createElement("input");
myInput.type = "text";
myInput.name = "sim";
myInput.value = JSON.stringify(/*data to post goes here*/);
myForm.appendChild(myInput);

document.body.appendChild(myForm);
myForm.submit();
$(myForm).hide();

Solution 4:

You need to use a BlobBuilder in that case.

From: https://github.com/bpampuch/pdfmake/issues/294#issuecomment-104029716

try {
   blob = newBlob([result], { type: 'application/pdf' });
}
catch (e) {
   // Old browser, need to use blob builderwindow.BlobBuilder = window.BlobBuilder ||
                        window.WebKitBlobBuilder ||
                        window.MozBlobBuilder ||
                        window.MSBlobBuilder;
   if (window.BlobBuilder) {
       var bb = newBlobBuilder();
       bb.append(result);
       blob = bb.getBlob("application/pdf");
   }
}

Solution 5:

After much searching this worked for me on IE, Edge and Chrome

var xhr = newXMLHttpRequest();

  xhr.onloadstart = function (ev) {
    xhr.responseType = "blob";
  };

  xhr.onreadystatechange = function () {
    if (xhr.readyState === 4 && xhr.status === 200) {
      if (!window.navigator.msSaveOrOpenBlob) {
        var url = (window.URL || window.webkitURL).createObjectURL(xhr.response);
        var aLink = document.createElement("a");
        document.body.appendChild(aLink);
        aLink.href = url;
        aLink.download = filename;
        aLink.click();
      } else {
        var fileData = [xhr.response];
        blobObject = newBlob(fileData);
        window.navigator.msSaveOrOpenBlob(blobObject, filename);
      }
    }
  };

Post a Comment for "Invalidstateerror In Internet Explorer 11 During Blob Creation"