@@ -39,19 +39,18 @@ export default function upload(option: UploadRequestOption) {
39
39
const formData = new FormData ( ) ;
40
40
41
41
if ( option . data ) {
42
- Object . keys ( option . data ) . forEach ( key => {
43
- const value = option . data [ key ] ;
42
+ Object . entries ( option . data ) . forEach ( ( [ header , value ] ) => {
44
43
// support key-value array data
45
44
if ( Array . isArray ( value ) ) {
46
45
value . forEach ( item => {
47
46
// { list: [ 11, 22 ] }
48
47
// formData.append('list[]', 11);
49
- formData . append ( `${ key } []` , item ) ;
48
+ formData . append ( `${ header } []` , item ) ;
50
49
} ) ;
51
50
return ;
52
51
}
53
52
54
- formData . append ( key , value as string | Blob ) ;
53
+ formData . append ( header , value as string | Blob ) ;
55
54
} ) ;
56
55
}
57
56
@@ -91,11 +90,9 @@ export default function upload(option: UploadRequestOption) {
91
90
xhr . setRequestHeader ( 'X-Requested-With' , 'XMLHttpRequest' ) ;
92
91
}
93
92
94
- Object . keys ( headers ) . forEach ( h => {
95
- if ( headers [ h ] !== null ) {
96
- xhr . setRequestHeader ( h , headers [ h ] ) ;
97
- }
98
- } ) ;
93
+ Object . entries ( headers )
94
+ . filter ( ( [ header , value ] ) => value !== null )
95
+ . forEach ( ( [ header , value ] ) => xhr . setRequestHeader ( header , value ) ) ;
99
96
100
97
xhr . send ( formData ) ;
101
98
0 commit comments