@@ -39,19 +39,18 @@ export default function upload(option: UploadRequestOption) {
3939 const formData = new FormData ( ) ;
4040
4141 if ( option . data ) {
42- Object . keys ( option . data ) . forEach ( key => {
43- const value = option . data [ key ] ;
42+ Object . entries ( option . data ) . forEach ( ( [ header , value ] ) => {
4443 // support key-value array data
4544 if ( Array . isArray ( value ) ) {
4645 value . forEach ( item => {
4746 // { list: [ 11, 22 ] }
4847 // formData.append('list[]', 11);
49- formData . append ( `${ key } []` , item ) ;
48+ formData . append ( `${ header } []` , item ) ;
5049 } ) ;
5150 return ;
5251 }
5352
54- formData . append ( key , value as string | Blob ) ;
53+ formData . append ( header , value as string | Blob ) ;
5554 } ) ;
5655 }
5756
@@ -91,11 +90,9 @@ export default function upload(option: UploadRequestOption) {
9190 xhr . setRequestHeader ( 'X-Requested-With' , 'XMLHttpRequest' ) ;
9291 }
9392
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 ) ) ;
9996
10097 xhr . send ( formData ) ;
10198
0 commit comments