I tried to load the base64 image string into array by <input type="file"/>
I am sure the string is in the array but when I call the array element the console callback is undefined.
as following my code:
fileChange(event){
if (event.target.files && event.target.files[0]) {
let imageFiles = [];
for (var i = 0; i < event.target.files.length; i++) {
let reader = new FileReader();
reader.readAsDataURL(event.target.files[i]);
reader.onload = (e) => {
imageFiles[i] = e.target.result;
console.log(e.target.result);
};
}
console.log(imageFiles);
console.log(imageFiles[0]);
}
}
//console result:
//"base64 string"
//[]-> 0: "base64 string"
//undefined
I think it because the base64 string is too long, but I have no idea to solve the problem.
It's some ways to solve it?