Created
February 3, 2020 16:42
-
-
Save praveen-vishnu/d1dddb836a3317d0180acf1d5a983ccb to your computer and use it in GitHub Desktop.
Convert an image url to a base64 data URL
This file contains 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
this.toDataURL(this.data.photoUrl, (dataUrl) => { | |
console.log(dataUrl); | |
}) | |
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