Created
February 9, 2023 11:48
-
-
Save zoutepopcorn/0cb66e6fd64fce93b796b7a8830076a6 to your computer and use it in GitHub Desktop.
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
const reader = (blob) => { | |
return new Promise((resolve, reject) => { | |
const reader = new FileReader() | |
reader.onloadend = () => resolve(reader.result) | |
reader.onerror = reject | |
reader.readAsDataURL(blob) | |
}) | |
} | |
const toDataURL = async (url) => { | |
const FETCH = await fetch(url); | |
const BLOB = await FETCH.blob(); | |
return await reader(BLOB); | |
} | |
toDataURL('https://www.gravatar.com/avatar/d50c83cc0c6523b4d3f6085295c953e0') | |
.then(dataUrl => { | |
console.log('RESULT:', dataUrl) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment