Skip to content

Instantly share code, notes, and snippets.

@ariona
Created October 9, 2020 10:43
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 ariona/876cd10530ddbb2f69dcfa3f26b3a985 to your computer and use it in GitHub Desktop.
Save ariona/876cd10530ddbb2f69dcfa3f26b3a985 to your computer and use it in GitHub Desktop.
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