Created
February 23, 2018 19:14
-
-
Save wescleymatos/0f3b54584ae91a572d90cf5d4255c0cb to your computer and use it in GitHub Desktop.
Converter link de uma imagem para base64
This file contains hidden or 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 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