diff --git a/src/lib/file-uploader.js b/src/lib/file-uploader.js index dec463d6d81a1ca887349010843472bb8e3b2c99..483f31edf61c95a08d6aa38522df9eda52d0aac7 100644 --- a/src/lib/file-uploader.js +++ b/src/lib/file-uploader.js @@ -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); }; /**