Add fallback to BlobBuilder API when Blob constructor is missing

This commit is contained in:
Sean Nichols 2017-05-08 15:34:46 -04:00
parent 4e6badc548
commit 2ed09bade2

View File

@ -96,8 +96,25 @@ ImageJob.prototype = {
headers: this.ajaxHeaders,
responseType: "arraybuffer",
success: function(request) {
// Make the raw data into a blob
var blb = new window.Blob([request.response]);
var blb;
// Make the raw data into a blob.
// BlobBuilder fallback adapted from
// http://stackoverflow.com/questions/15293694/blob-constructor-browser-compatibility
try {
blb = new window.Blob([request.response]);
} catch (e) {
var BlobBuilder = (
window.BlobBuilder ||
window.WebKitBlobBuilder ||
window.MozBlobBuilder ||
window.MSBlobBuilder
);
if (e.name === 'TypeError' && BlobBuilder) {
var bb = new BlobBuilder();
bb.append(request.response);
blb = bb.getBlob();
}
}
// If the blob is empty for some reason consider the image load a failure.
if (blb.size === 0) {
self.errorMsg = "Empty image response.";