1
Talk, you guys, blz?
Today I tried to make a Dropzone clone just to test the File and Filereader api. However, I think I’m missing some loop concept.
According to the loop interaction, I take the current file extension to display an image-free Thumb if it is different from (jpg|png|jpeg).
The problem is that the line that checks is always picking up the extension of the last array item
Follows:
for (var i = 0; i < files.length; i++) {
var fr = new FileReader();
fr.readAsDataURL(files[i]);
var name = files[i].name;
var size = files[i].size / 1000;
var type = files[i].type;
var ext = name.substr(name.lastIndexOf("."), name.length);
fr.onload = function(r) {
// aqui
var tag = ext.match(/\.(jpg|jpeg|png)/) ? "img" : "div";
console.log(tag);
m += `<div class="up-item hint--bottom" aria-label="deu bom">
<${tag} src="${r.target.result}" />
</div>`;
console.log(m);
};
}
It would not be better to declare in the fr.onload loop before Fs.readAsDataURL?
– Maury Developer