Skip to content

Commit 65756fc

Browse files
committed
Load files one at a time to enforce load order
1 parent 7eabc4d commit 65756fc

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/lib/file-uploader.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,25 @@ const extractFileName = function (nameExt) {
2121
* @param {Function} onload The function that handles loading the file
2222
*/
2323
const handleFileUpload = function (fileInput, onload) {
24-
const readFile = file => {
25-
const reader = new FileReader();
26-
reader.onload = () => {
24+
const readFile = (i, files) => {
25+
if (i === files.length) {
2726
// Reset the file input value now that we have everything we need
2827
// so that the user can upload the same sound multiple times if
2928
// they choose
3029
fileInput.value = null;
30+
return;
31+
}
32+
const file = files[i];
33+
const reader = new FileReader();
34+
reader.onload = () => {
3135
const fileType = file.type;
3236
const fileName = extractFileName(file.name);
33-
3437
onload(reader.result, fileType, fileName);
38+
readFile(i + 1, files);
3539
};
3640
reader.readAsArrayBuffer(file);
3741
};
38-
for (let i = 0; i < fileInput.files.length; i++) {
39-
readFile(fileInput.files[i]);
40-
}
42+
readFile(0, fileInput.files);
4143
};
4244

4345
/**

0 commit comments

Comments
 (0)