File tree Expand file tree Collapse file tree 1 file changed +9
-7
lines changed Expand file tree Collapse file tree 1 file changed +9
-7
lines changed Original file line number Diff line number Diff line change @@ -21,23 +21,25 @@ const extractFileName = function (nameExt) {
21
21
* @param {Function } onload The function that handles loading the file
22
22
*/
23
23
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 ) {
27
26
// Reset the file input value now that we have everything we need
28
27
// so that the user can upload the same sound multiple times if
29
28
// they choose
30
29
fileInput . value = null ;
30
+ return ;
31
+ }
32
+ const file = files [ i ] ;
33
+ const reader = new FileReader ( ) ;
34
+ reader . onload = ( ) => {
31
35
const fileType = file . type ;
32
36
const fileName = extractFileName ( file . name ) ;
33
-
34
37
onload ( reader . result , fileType , fileName ) ;
38
+ readFile ( i + 1 , files ) ;
35
39
} ;
36
40
reader . readAsArrayBuffer ( file ) ;
37
41
} ;
38
- for ( let i = 0 ; i < fileInput . files . length ; i ++ ) {
39
- readFile ( fileInput . files [ i ] ) ;
40
- }
42
+ readFile ( 0 , fileInput . files ) ;
41
43
} ;
42
44
43
45
/**
You can’t perform that action at this time.
0 commit comments