I am transferring image files from XMLHttpRequest for this readfiles (files) function using dataTransfer
what I'm trying to do is preview the images and image file names at the same time and in the same string code inside the reader.onload () function .
and because more than 1 function file will be transferred, I threw them into a loop
The problem is that I am trying to view images using readDataURL , but file names cannot be viewed. I think because the reader.onload () function stopped for a loop from looping through image files.
Here is my code
function readfiles(files) {
var x;
for(x = 0; x < files.length; x = x + 1) {
var reader = new FileReader();
reader.readAsDataURL(files[x]);
reader.onload = function(e) {
console.log(e.target.result);
console.log(files[x].name);
}
}
}
searched for a solution for about 5 hours, any help!
source
share