Created
November 18, 2021 16:48
-
-
Save kingisaac95/aeebdf5060bb31409fc34a0ba549f5c0 to your computer and use it in GitHub Desktop.
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
const uploadFile = ({ | |
event, | |
onComplete | |
}: { | |
event: ChangeEvent<HTMLInputElement>; | |
onComplete: (file: File, base64File: string) => void; | |
}) => { | |
event.preventDefault(); | |
let base64File: string; | |
const file: File | null = event.target.files ? event.target.files[0] : null; | |
if (file) { | |
const reader = new FileReader(); | |
reader.readAsDataURL(file); | |
reader.onload = () => { | |
base64File = btoa(reader.result as string); | |
onComplete(file, base64File); | |
}; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment