Created
October 5, 2021 14:01
-
-
Save dmitriyzyuzin/f6f0de637f0d0e6588320b90e2ace93d to your computer and use it in GitHub Desktop.
Load image and convert to 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
const loadIconAndConvertIconToBase64 = url => { | |
return fetch(url) | |
.then(response => response.blob()) | |
.then(blob => new Promise((resolve, reject) => { | |
const reader = new FileReader() | |
reader.onloadend = () => resolve(reader.result) | |
reader.onerror = reject | |
reader.readAsDataURL(blob) | |
})); | |
} | |
loadIconAndConvertIconToBase64('https://domain.qwewdsfsdf/awesome.png') | |
.then(b64 => { | |
console.log('b64: ', b64) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment