1. function getBase64(file) {
    2. var reader = new FileReader();
    3. reader.readAsDataURL(file);
    4. reader.onload = function () {
    5. console.log(reader.result);
    6. };
    7. reader.onerror = function (error) {
    8. console.log('Error: ', error);
    9. };
    10. }
    11. var file = document.querySelector('#files > input[type="file"]').files[0];
    12. getBase64(file); // prints the base64 string