Created
July 15, 2016 06:55
-
-
Save anhulife/3fb1a65550aed03073b2fcd663eeebcf to your computer and use it in GitHub Desktop.
loadToDataURL
This file contains 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
function loadToDataURL(url, callback) { | |
var xhr = new XMLHttpRequest(); | |
xhr.responseType = 'blob'; | |
xhr.onload = function() { | |
var reader = new FileReader(); | |
reader.onloadend = function () { | |
callback(reader.result); | |
reader = null; | |
} | |
reader.readAsDataURL(xhr.response); | |
xhr = null; | |
}; | |
xhr.open('GET', url); | |
xhr.send(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment