Created
December 26, 2020 09:41
-
-
Save lil12t/7ea68910952794c66479035b387070d8 to your computer and use it in GitHub Desktop.
Get base64 from File | convert file to base64
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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