Skip to content

Instantly share code, notes, and snippets.

@mccabiles
Created September 6, 2019 13:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mccabiles/8ae33902c1f6433948137c3ce06a1577 to your computer and use it in GitHub Desktop.
Save mccabiles/8ae33902c1f6433948137c3ce06a1577 to your computer and use it in GitHub Desktop.
Get data from file for use with <image> src.
const readFileData = (file) => {
return new Promise(resolve => {
if (!file instanceof File)
return resolve(file);
const reader = new FileReader();
reader.addEventListener('load', function() {
resolve(this.result);
});
reader.readAsDataURL(file);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment