@@ -15,6 +15,7 @@ import { AI21EnvConfig } from './EnvConfig';
15
15
import { createFetchInstance , createFilesHandlerInstance } from './runtime' ;
16
16
import { Fetch } from 'fetch' ;
17
17
import { BaseFilesHandler } from 'files/BaseFilesHandler' ;
18
+ import { FormDataRequest } from 'types/API' ;
18
19
19
20
const validatePositiveInteger = ( name : string , n : unknown ) : number => {
20
21
if ( typeof n !== 'number' || ! Number . isInteger ( n ) ) {
@@ -79,27 +80,27 @@ export abstract class APIClient {
79
80
return this . prepareAndExecuteRequest ( 'delete' , path , opts ) ;
80
81
}
81
82
82
- async upload < Req , Rsp > ( path : string , file : FilePathOrFileObject , opts ?: RequestOptions < Req > ) : Promise < Rsp > {
83
- const formDataRequest = await this . filesHandler . prepareFormDataRequest ( file ) ;
84
-
85
- if ( opts ?. body ) {
86
- // eslint-disable-next-line @typescript-eslint/no-explicit- any
87
- appendBodyToFormData ( formDataRequest . formData , opts . body as Record < string , any > ) ;
88
- }
89
-
90
- const headers = {
91
- ...opts ? .headers ,
92
- ... formDataRequest . headers ,
93
- } ;
94
-
95
- const options : FinalRequestOptions = {
96
- method : 'post' ,
97
- path : path ,
98
- body : formDataRequest . formData ,
99
- headers ,
100
- } ;
101
-
102
- return this . performRequest ( options ) . then ( ( response ) => this . fetch . handleResponse < Rsp > ( response ) as Rsp ) ;
83
+ upload < Req , Rsp > ( path : string , file : FilePathOrFileObject , opts ?: RequestOptions < Req > ) : Promise < Rsp > {
84
+ return this . filesHandler . prepareFormDataRequest ( file ) . then ( ( formDataRequest : FormDataRequest ) => {
85
+ if ( opts ?. body ) {
86
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
87
+ appendBodyToFormData ( formDataRequest . formData , opts . body as Record < string , any > ) ;
88
+ }
89
+
90
+ const headers = {
91
+ ... opts ?. headers ,
92
+ ...formDataRequest . headers ,
93
+ } ;
94
+
95
+ const options : FinalRequestOptions = {
96
+ method : 'post' ,
97
+ path : path ,
98
+ body : formDataRequest . formData ,
99
+ headers ,
100
+ } ;
101
+
102
+ return this . performRequest ( options ) . then ( ( response ) => this . fetch . handleResponse < Rsp > ( response ) as Rsp ) ;
103
+ } ) ;
103
104
}
104
105
105
106
protected getUserAgent ( ) : string {
0 commit comments