@@ -64,14 +64,17 @@ export abstract class APIClient {
64
64
return this . makeRequest ( 'delete' , path , opts ) ;
65
65
}
66
66
67
- upload < Req , Rsp > ( path : string , filePath : string , opts ?: RequestOptions < Req > ) : Promise < Rsp > {
67
+ async upload < Req , Rsp > ( path : string , filePath : string , opts ?: RequestOptions < Req > ) : Promise < Rsp > {
68
68
const formDataRequest = this . makeFormDataRequest ( path , filePath , opts ) ;
69
- return this . performRequest ( formDataRequest ) . then (
70
- ( response ) => this . fetch . handleResponse < Rsp > ( response ) as Rsp ,
71
- ) ;
69
+ const response = await this . performRequest ( formDataRequest ) ;
70
+ return this . fetch . handleResponse < Rsp > ( response ) as Rsp ;
72
71
}
73
72
74
- protected makeFormDataRequest < Req > ( path : string , filePath : string , opts ?: RequestOptions < Req > ) : FinalRequestOptions {
73
+ protected makeFormDataRequest < Req > (
74
+ path : string ,
75
+ filePath : string ,
76
+ opts ?: RequestOptions < Req > ,
77
+ ) : FinalRequestOptions {
75
78
const formData = new FormData ( ) ;
76
79
const fileStream = createReadStream ( filePath ) ;
77
80
const fileName = getBasename ( filePath ) ;
@@ -83,7 +86,7 @@ export abstract class APIClient {
83
86
const body = opts . body as Record < string , any > ;
84
87
for ( const [ key , value ] of Object . entries ( body ) ) {
85
88
if ( Array . isArray ( value ) ) {
86
- value . forEach ( item => formData . append ( key , item ) ) ;
89
+ value . forEach ( ( item ) => formData . append ( key , item ) ) ;
87
90
} else {
88
91
formData . append ( key , value ) ;
89
92
}
@@ -92,12 +95,8 @@ export abstract class APIClient {
92
95
93
96
const headers = {
94
97
...opts ?. headers ,
95
- 'Content-Type' : `multipart/form-data; boundary=${ formData . getBoundary ( ) } `
98
+ 'Content-Type' : `multipart/form-data; boundary=${ formData . getBoundary ( ) } ` ,
96
99
} ;
97
- console . log ( headers ) ;
98
- console . log ( "-------------------------" ) ;
99
- console . log ( formData . getHeaders ( ) ) ;
100
- console . log ( "-------------------------" ) ;
101
100
102
101
const options : FinalRequestOptions = {
103
102
method : 'post' ,
0 commit comments