Skip to content

Instantly share code, notes, and snippets.

@HaNdTriX
Last active February 18, 2021 20:02
Show Gist options
  • Save HaNdTriX/bdffd11761701fbeba27f23e9a69515f to your computer and use it in GitHub Desktop.
Save HaNdTriX/bdffd11761701fbeba27f23e9a69515f to your computer and use it in GitHub Desktop.
Example of converting a file to a dataURL in ES6
const toDataURL = url => 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)
}))
@HaNdTriX
Copy link
Author

HaNdTriX commented Mar 8, 2017

@rohmanhm I have updated the gist. Totally missed that 😳

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment