Last active
October 27, 2020 07:48
-
-
Save almond-bongbong/4aeb9227f8a79d8d593a8b5e73fa5eb2 to your computer and use it in GitHub Desktop.
File object to base64 string
This file contains 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 | Blob): Promise<string> => ( | |
new Promise((resolve, reject) => { | |
const reader = new FileReader(); | |
reader.readAsDataURL(file); | |
reader.onload = (): void => { | |
resolve(reader.result as string); | |
}; | |
reader.onerror = (error): void => { | |
reject(error); | |
}; | |
}) | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment