I’m new to java script and I can’t understand:
Why this print base64 from file:
function getBase64(file) {
var reader = new FileReader();
reader.readAsDataURL(file);
reader.onload = function () {
console.log(reader.result); // base64string exist only here
};
reader.onerror = function (error) {
console.log('Error: ', error);
};
}
But almost same:
function toBase64 (file) {
var reader = new FileReader();
reader.readAsDataURL(file);
return reader.result;
}
Return null
I don’t understand what’s going
How can I simply convert a file to a string without any extra expressions (like promises), just call -> return, like python? Like that:
var justBase64String = justConvertFileToBase64(file)
P.S. i get my file from input:
var file = document.getElementById('face-input').files[0]