Created
February 23, 2022 04:52
-
-
Save lazerg/c975ab542499a992e866d0975a32411c to your computer and use it in GitHub Desktop.
Promise based file to base64 conversion
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
/** | |
* Converts file to base64 | |
* | |
* @param {File} file | |
* @return {Promise<String>} | |
*/ | |
export default file => { | |
return new Promise(resolve => { | |
const reader = new FileReader(); | |
reader.readAsDataURL(file); | |
reader.onload = () => resolve(reader.result); | |
}) | |
} |
A very helpful helper for handling files. Thank you, what we needed.
Bravo! A very Useful hint!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Approximately usage: