Skip to content

Instantly share code, notes, and snippets.

@zoutepopcorn
Created February 9, 2023 11:48
Show Gist options
  • Save zoutepopcorn/0cb66e6fd64fce93b796b7a8830076a6 to your computer and use it in GitHub Desktop.
Save zoutepopcorn/0cb66e6fd64fce93b796b7a8830076a6 to your computer and use it in GitHub Desktop.
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