Skip to content

Instantly share code, notes, and snippets.

@ariona
Created Oct 9, 2020
Embed
What would you like to do?
toBase64 from URL
/* make sure the target URL CORS is allowed */
function toDataUrl(url, callback) {
var xhr = new XMLHttpRequest();
xhr.onload = function() {
var reader = new FileReader();
reader.onloadend = function() {
callback(reader.result);
}
reader.readAsDataURL(xhr.response);
};
xhr.open('GET', url);
xhr.responseType = 'blob';
xhr.send();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment