Working with Blob data in Internet Explorer 11

Posted: (EET/GMT+2)

 

Internet Explorer 11 supports Blob and File APIs, which is great for situations where you need to store some data on the user's computer. If you want to download or display a Blob from JavaScript, use the "msSaveOrOpenBlob" function for compatibility.

Let's take a simple example, saving a generated CSV file to disk:

var csv = "Id,Name\r\n1,Alice\r\n2,Bob\r\n";
var blob = new Blob([csv], { type: "text/csv" });

if (window.navigator && window.navigator.msSaveOrOpenBlob) {
    // Internet Explorer 11 (IE11)
    window.navigator.msSaveOrOpenBlob(blob, "data.csv");
}

For displaying images from a Blob, IE11 requires the Blob to be served with the correct MIME type and doesn't fully support URL.revokeObjectURL() on detached DOM nodes, so test carefully when dynamically removing images.