Skip to content

Instantly share code, notes, and snippets.

@marco-souza
Created July 14, 2020 17:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save marco-souza/552f94f87059fdeeef35e95d1680de84 to your computer and use it in GitHub Desktop.
Save marco-souza/552f94f87059fdeeef35e95d1680de84 to your computer and use it in GitHub Desktop.
Convert File to Base64 in JavaScript/TypeScript
export const toBase64 = (file: File) =>
new Promise((resolve, reject) => {
const reader = new FileReader();
reader.readAsDataURL(file);
reader.onload = () => resolve(reader.result);
reader.onerror = (error) => reject(error);
});
@AlexandreSantAnaLangunno

Muito obrigado!

@marco-souza
Copy link
Author

tmj 👍

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