Created
December 12, 2020 19:35
-
-
Save klipitkas/8629248aa37bb497351ea7701603bc36 to your computer and use it in GitHub Desktop.
Revisions
-
klipitkas created this gist
Dec 12, 2020 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,25 @@ <html> <body> <form> <input type="file" class="image" name="image"> </form> <script> const image = document.querySelector('.image'); const toBase64 = file => new Promise((resolve, reject) => { const reader = new FileReader(); reader.readAsDataURL(file); reader.onload = () => resolve(reader.result); reader.onerror = error => reject(error); }); image.addEventListener('change', async (event) => { toBase64(event.target.files[0]).then((b64) => { console.log(b64); }).catch((error) => { console.error(error); }) }); </script> </body> </html>