File tree Expand file tree Collapse file tree 2 files changed +9
-15
lines changed Expand file tree Collapse file tree 2 files changed +9
-15
lines changed Original file line number Diff line number Diff line change @@ -43,11 +43,8 @@ var FileInput = function (_React$Component) {
43
43
44
44
45
45
_this . handleChange = function ( e ) {
46
- var files = [ ] ;
47
- for ( var i = 0 ; i < e . target . files . length ; i ++ ) {
48
- // Convert to Array.
49
- files . push ( e . target . files [ i ] ) ;
50
- }
46
+ var files = Array . prototype . slice . call ( e . target . files ) ; // Convert into Array
47
+ var readAs = ( _this . props . as || 'url' ) . toLowerCase ( ) ;
51
48
52
49
// Build Promise List, each promise resolved by FileReader.onload.
53
50
Promise . all ( files . map ( function ( file ) {
@@ -60,7 +57,7 @@ var FileInput = function (_React$Component) {
60
57
} ;
61
58
62
59
// Read the file with format based on this.props.as.
63
- switch ( ( _this . props . as || 'url' ) . toLowerCase ( ) ) {
60
+ switch ( readAs ) {
64
61
case 'binary' :
65
62
{
66
63
reader . readAsBinaryString ( file ) ;
@@ -94,7 +91,7 @@ var FileInput = function (_React$Component) {
94
91
} ;
95
92
96
93
var win = ( typeof window === 'undefined' ? 'undefined' : _typeof ( window ) ) === 'object' ? window : { } ;
97
- if ( ( typeof window === 'undefined' ? 'undefined' : _typeof ( window ) ) === 'object' && ( ! win . File || ! win . FileReader || ! win . FileList || ! win . Blob ) ) {
94
+ if ( ! win . File || ! win . FileReader || ! win . FileList || ! win . Blob ) {
98
95
console . warn ( '[react-file-reader-input] Some file APIs detected as not supported.' + ' File reader functionality may not fully work.' ) ;
99
96
}
100
97
return _this ;
Original file line number Diff line number Diff line change @@ -14,20 +14,17 @@ export default class FileInput extends React.Component {
14
14
super ( props ) ;
15
15
16
16
const win = typeof window === 'object' ? window : { } ;
17
- if ( ( typeof window === 'object' ) && ( ! win . File || ! win . FileReader || ! win . FileList || ! win . Blob ) ) {
17
+ if ( ! win . File || ! win . FileReader || ! win . FileList || ! win . Blob ) {
18
18
console . warn (
19
19
'[react-file-reader-input] Some file APIs detected as not supported.' +
20
20
' File reader functionality may not fully work.'
21
21
) ;
22
22
}
23
23
}
24
24
25
- handleChange = e => {
26
- const files = [ ] ;
27
- for ( let i = 0 ; i < e . target . files . length ; i ++ ) {
28
- // Convert to Array.
29
- files . push ( e . target . files [ i ] ) ;
30
- }
25
+ handleChange = ( e ) => {
26
+ const files = Array . prototype . slice . call ( e . target . files ) ; // Convert into Array
27
+ const readAs = ( this . props . as || 'url' ) . toLowerCase ( ) ;
31
28
32
29
// Build Promise List, each promise resolved by FileReader.onload.
33
30
Promise . all ( files . map ( file => new Promise ( ( resolve , reject ) => {
@@ -39,7 +36,7 @@ export default class FileInput extends React.Component {
39
36
} ;
40
37
41
38
// Read the file with format based on this.props.as.
42
- switch ( ( this . props . as || 'url' ) . toLowerCase ( ) ) {
39
+ switch ( readAs ) {
43
40
case 'binary' : {
44
41
reader . readAsBinaryString ( file ) ;
45
42
break ;
You can’t perform that action at this time.
0 commit comments