@@ -233,6 +233,10 @@ function isBlob(value: any): value is Blob {
233
233
return value instanceof Blob;
234
234
}
235
235
236
+ function isFormData(value: any): value is FormData {
237
+ return value instanceof FormData;
238
+ }
239
+
236
240
function base64(str: string): string {
237
241
try {
238
242
return btoa(str);
@@ -347,7 +351,7 @@ async function getHeaders(options: ApiRequestOptions): Promise<Headers> {
347
351
headers.append('Content-Type', options.body.type || 'application/octet-stream');
348
352
} else if (isString(options.body)) {
349
353
headers.append('Content-Type', 'text/plain');
350
- } else {
354
+ } else if (!isFormData(options.body)) {
351
355
headers.append('Content-Type', 'application/json');
352
356
}
353
357
}
@@ -359,7 +363,7 @@ function getRequestBody(options: ApiRequestOptions): BodyInit | undefined {
359
363
if (options.body) {
360
364
if (options.mediaType?.includes('/json')) {
361
365
return JSON.stringify(options.body)
362
- } else if (isString(options.body) || isBlob(options.body)) {
366
+ } else if (isString(options.body) || isBlob(options.body) || isFormData(options.body) ) {
363
367
return options.body;
364
368
} else {
365
369
return JSON.stringify(options.body);
@@ -2896,6 +2900,10 @@ function isBlob(value: any): value is Blob {
2896
2900
return value instanceof Blob;
2897
2901
}
2898
2902
2903
+ function isFormData(value: any): value is FormData {
2904
+ return value instanceof FormData;
2905
+ }
2906
+
2899
2907
function base64(str: string): string {
2900
2908
try {
2901
2909
return btoa(str);
@@ -3010,7 +3018,7 @@ async function getHeaders(options: ApiRequestOptions): Promise<Headers> {
3010
3018
headers.append('Content-Type', options.body.type || 'application/octet-stream');
3011
3019
} else if (isString(options.body)) {
3012
3020
headers.append('Content-Type', 'text/plain');
3013
- } else {
3021
+ } else if (!isFormData(options.body)) {
3014
3022
headers.append('Content-Type', 'application/json');
3015
3023
}
3016
3024
}
@@ -3022,7 +3030,7 @@ function getRequestBody(options: ApiRequestOptions): BodyInit | undefined {
3022
3030
if (options.body) {
3023
3031
if (options.mediaType?.includes('/json')) {
3024
3032
return JSON.stringify(options.body)
3025
- } else if (isString(options.body) || isBlob(options.body)) {
3033
+ } else if (isString(options.body) || isBlob(options.body) || isFormData(options.body) ) {
3026
3034
return options.body;
3027
3035
} else {
3028
3036
return JSON.stringify(options.body);
0 commit comments