Skip to content

Instantly share code, notes, and snippets.

@anhulife
Created July 15, 2016 06:55
Show Gist options
  • Save anhulife/3fb1a65550aed03073b2fcd663eeebcf to your computer and use it in GitHub Desktop.
Save anhulife/3fb1a65550aed03073b2fcd663eeebcf to your computer and use it in GitHub Desktop.
loadToDataURL
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