Skip to content
Snippets Groups Projects
Commit 65756fcc authored by Paul Kaplan's avatar Paul Kaplan
Browse files

Load files one at a time to enforce load order

parent 7eabc4d9
No related branches found
No related tags found
No related merge requests found
......@@ -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);
};
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment