1const toBase64 = file => new Promise((resolve, reject) => {
2 const reader = new FileReader();
3 reader.readAsDataURL(file);
4 reader.onload = () => resolve(reader.result);
5 reader.onerror = error => reject(error);
6});
7
8async function Main() {
9 const file = document.querySelector('#myfile').files[0];
10 console.log(await toBase64(file));
11}
12
13Main();
14