Load files one at a time to enforce load order
This commit is contained in:
1 parent
7eabc4d9cd
commit
65756fcc50
1 file changed
+9
-7
@@ -21,23 +21,25 @@ const extractFileName = function (nameExt) {
|
||||
* @param {Function} onload The function that handles loading the file
|
||||
*/
|
||||
const handleFileUpload = function (fileInput, onload) {
|
||||
const readFile = file => {
|
||||
const reader = new FileReader();
|
||||
reader.onload = () => {
|
||||
const readFile = (i, files) => {
|
||||
if (i === files.length) {
|
||||
// Reset the file input value now that we have everything we need
|
||||
// so that the user can upload the same sound multiple times if
|
||||
// they choose
|
||||
fileInput.value = null;
|
||||
return;
|
||||
}
|
||||
const file = files[i];
|
||||
const reader = new FileReader();
|
||||
reader.onload = () => {
|
||||
const fileType = file.type;
|
||||
const fileName = extractFileName(file.name);
|
||||
|
||||
onload(reader.result, fileType, fileName);
|
||||
readFile(i + 1, files);
|
||||
};
|
||||
reader.readAsArrayBuffer(file);
|
||||
};
|
||||
for (let i = 0; i < fileInput.files.length; i++) {
|
||||
readFile(fileInput.files[i]);
|
||||
}
|
||||
readFile(0, fileInput.files);
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user