Last active
January 1, 2020 18:26
-
-
Save Prinzhorn/5a9d7db4e4fb9372b2e6 to your computer and use it in GitHub Desktop.
Internet Explorer 11 Blob from DataView throws InvalidStateError
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 buffer = new ArrayBuffer(8); | |
var left = new DataView(buffer, 0, 4); | |
try { | |
//Throws InvalidStateError in IE 11. | |
//It does work if we use a specific view like Uint8Array and not the generic DataView contructor. | |
new Blob([left]); | |
} catch(ex) { | |
alert(ex.message); | |
} |
I couldn't get it to work with Uint8Array for IE11 on Windows 8. Here is my solution:
try {
var blob = new Blob([data], {
type: "text/csv;charset=utf-8"
});
} catch (e) {
if (e.name == "InvalidStateError") {
// InvalidStateError (tested on Win8 IE11)
var bb = new MSBlobBuilder();
bb.append(data);
var blob = bb.getBlob('text/csv;charset=utf-8');
} else {
// We're screwed, blob constructor unsupported entirely
}
}
@tchansen - I tried your solution this morning and it works - thank you 👍
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For my use case (passing the blob to
createObjectURL
) I could just replaceDataView
withUint8Array
to make it work in IE.