mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-12-11 07:12:46 +00:00
[typescript-fetch] Fix uploading files (#2900)
* [typescript-fetch] Fix uploading files * Check for Blob instead of File * Update samples * Update samples * Update samples * Update samples * Regenerate samples * Bug * Manually fix samples * Implement support for Buffer and Blob in a backwards-compatible way * Rework how blob and buffer instance checking works * Check for Blob/Buffer existence properly * Avoid using Buffer and Blob in type declarations * Remove Buffer support * Update samples/client/petstore/typescript-fetch/tests/default/test/PetApi.ts Co-Authored-By: Esteban Marin <estebanmarin@gmx.ch> * Update samples/client/petstore/typescript-fetch/tests/default/test/PetApi.ts Co-Authored-By: Esteban Marin <estebanmarin@gmx.ch>
This commit is contained in:
committed by
William Cheng
parent
ddf21f0ca5
commit
c509d9897a
@@ -3,6 +3,8 @@
|
||||
|
||||
export const BASE_PATH = "{{{basePath}}}".replace(/\/+$/, "");
|
||||
|
||||
const isBlob = (value: any) => typeof Blob !== 'undefined' && value instanceof Blob;
|
||||
|
||||
/**
|
||||
* This is the base class for all generated API classes.
|
||||
*/
|
||||
@@ -47,7 +49,9 @@ export class BaseAPI {
|
||||
// do not handle correctly sometimes.
|
||||
url += '?' + querystring(context.query);
|
||||
}
|
||||
const body = context.body instanceof FormData ? context.body : JSON.stringify(context.body);
|
||||
const body = (context.body instanceof FormData || isBlob(context.body))
|
||||
? context.body
|
||||
: JSON.stringify(context.body);
|
||||
const init = {
|
||||
method: context.method,
|
||||
headers: context.headers,
|
||||
|
||||
Reference in New Issue
Block a user