I use XMLHttpRequest
to generate Blob
from data URI using this code:
function dataUrlToBlob(dataUrl, callback) {
var xhr = new XMLHttpRequest;
xhr.open( 'GET', dataUrl);
xhr.responseType = 'arraybuffer';
xhr.onload = function(e) {
callback( new Blob( [this.response], {type: 'image/png'} ) );
};
xhr.send();
}
Usage:
dataUrlToBlob('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAC0lEQVQIW2NkAAIAAAoAAggA9GkAAAAASUVORK5CYII=', callback);
Everything works fine in every browser except Safari. It throws such an error:
[Error] XMLHttpRequest cannot load data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAC0lEQVQIW2NkAAIAAAoAAggA9GkAAAAASUVORK5CYII=. Cross origin requests are only supported for HTTP.
The question is, are there any ways to make this approach working in Safari?