Answers for "Convert file to base64 - ES6 modern js"

0

Convert file to base64 - ES6 modern js

const toBase64 = file => new Promise((resolve, reject) => {
    const reader = new FileReader();
    reader.readAsDataURL(file);
    reader.onload = () => resolve(reader.result);
    reader.onerror = error => reject(error);
});

async function Main() {
   const file = document.querySelector('#myfile').files[0];
   console.log(await toBase64(file));
}

Main();
Posted by: Guest on May-17-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language