Skip to content

Instantly share code, notes, and snippets.

@almond-bongbong
Last active October 27, 2020 07:48
Show Gist options
  • Save almond-bongbong/4aeb9227f8a79d8d593a8b5e73fa5eb2 to your computer and use it in GitHub Desktop.
Save almond-bongbong/4aeb9227f8a79d8d593a8b5e73fa5eb2 to your computer and use it in GitHub Desktop.
File object to base64 string
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