Skip to content

Instantly share code, notes, and snippets.

@mallowigi
Created January 18, 2017 08:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mallowigi/ecf0113c4918a82bcbf73cbc91c7883f to your computer and use it in GitHub Desktop.
Save mallowigi/ecf0113c4918a82bcbf73cbc91c7883f to your computer and use it in GitHub Desktop.
download image
APP.getImage = function() {
var r = new XMLHttpRequest();
r.open('GET', 'https://source.unsplash.com/category/nature/100x100', true);
r.responseType = 'arraybuffer';
r.onreadystatechange = function(){
if(this.readyState === XMLHttpRequest.DONE){
if (this.status === 200) {
var blb = new Blob( [this.response] , {type : 'image/jpeg'} ),
reader = new FileReader();
reader.addEventListener("load", function() {
var dataurl = this.result;
APP.setImage(dataurl);
}, false);
reader.readAsDataURL(blb);
}
}
};
r.send();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment