Skip to content

Instantly share code, notes, and snippets.

@wescleymatos
Created February 23, 2018 19:14
Show Gist options
  • Save wescleymatos/0f3b54584ae91a572d90cf5d4255c0cb to your computer and use it in GitHub Desktop.
Save wescleymatos/0f3b54584ae91a572d90cf5d4255c0cb to your computer and use it in GitHub Desktop.
Converter link de uma imagem para base64
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();
}
toDataUrl("https://s3-us-east-2.amazonaws.com/minhaigreja-production/images/articles/5/original/joao_capitulo_7_versiculo_53.jpg?1519132286", function(myBase64) {
console.log(myBase64); // myBase64 is the base64 string
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment