current position:Home>How do I ensure the file upload order when I use FileReader onload to upload files in JS

How do I ensure the file upload order when I use FileReader onload to upload files in JS

2022-02-02 19:50:55 CSDN Q & A

I am here JS Upload to OBS When because FileReader onload It's an asynchronous request So there will be a problem with the order of the files I upload
adopt var dicomList = event.target.files; All files obtained directly And then in for Loop this array

for (var i = 0; i < dicomList.length; i++) { 
                    var file = dicomList[i];                var files = dicomList[i];                let reader = new FileReader();                let fileName = file.name;                fruits.push(files);                 reader.readAsArrayBuffer(file);                                reader.onload = function(file) {.........

Used in circulation onload Method Uploaded in this method OBS Therefore, the order of file uploading is inconsistent




Refer to the answer 1:

Not directly for,for The asynchronous operation cannot control the sequence
Make a function loop call , You can refer to my reply in this question , similar , Just one is ajax, The main question is filereader
https://ask.csdn.net/questions/7480804




Refer to the answer 2:

copyright notice
author[CSDN Q & A],Please bring the original link to reprint, thank you.
https://en.primo.wiki/2022/02/202202021950537715.html

Random recommended