Skip to content

Instantly share code, notes, and snippets.

@lil12t
Created December 26, 2020 09:41
Show Gist options
  • Save lil12t/7ea68910952794c66479035b387070d8 to your computer and use it in GitHub Desktop.
Save lil12t/7ea68910952794c66479035b387070d8 to your computer and use it in GitHub Desktop.
Get base64 from File | convert file to base64
export const getBase64 = (file: File): Promise<string> =>
new Promise((resolve, reject) => {
const reader = new FileReader();
reader.readAsDataURL(file);
reader.onload = function (): void {
resolve(reader.result?.toString());
};
reader.onerror = function (error): void {
reject(error);
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment