This yent answer option manages multiple downloads and uses jquery:
HTML:
<form id="myform"> <p> <input id="myfile" name="files[]" multiple="" type="file" /> <textarea id="text" rows="20" cols="40">nothing loaded</textarea> </p> </form>
script:
$("#myfile").on("change", function (changeEvent) { for (var i = 0; i < changeEvent.target.files.length; ++i) { (function (file) { // Wrap current file in a closure. var loader = new FileReader(); loader.onload = function (loadEvent) { if (loadEvent.target.readyState != 2) return; if (loadEvent.target.error) { alert("Error while reading file " + file.name + ": " + loadEvent.target.error); return; } console.log(loadEvent.target.result.length); // Your text is in loadEvent.target.result }; loader.readAsText(file); })(changeEvent.target.files[i]); } });
Its useful to note:
- You must use one FileReader for each (parallel) file. Otherwise, you will see an exception, for example,
The object is already busy reading . - LoadEvent callbacks will be called in random order, probably depending on the size of the load.
- Closing loadEvent will see the value of
i that ended the loop. - FileReader results are not arrays; they do not have for each.
This jsfiddle daemon saves the load order by posting the div in the change handler.
ericP
source share