Created
January 18, 2017 08:39
-
-
Save mallowigi/ecf0113c4918a82bcbf73cbc91c7883f to your computer and use it in GitHub Desktop.
download image
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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