With HTML5 and FileReader/Blob I can convert from/to Blobs/dataURIs, but I'm wondering if I can download an image from a remote URL and convert it to a Blob (or a dataURI).
If this is possible, how would I do it?
I managed to do it myself:
var xhr = new XMLHttpRequest();
xhr.open('GET', attr.ngfDefaultSrc, true);
xhr.responseType = 'blob';
xhr.onload = function(e) {
if (this.status !== 200) return;
var blob = new Blob([this.response], {type: this.response.type});
//rest of the code that uses the blob goes here
};
xhr.send();
this.response is already a blob, and the mime should be set already by the Content-Type header, so you probably don't need the extra step of concating the blob into a new blob. var blob=this.response;
xhr.responseType="blob";