[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:
Jan Buchar
2019-05-31 08:15:32 +02:00
committed by William Cheng
parent ddf21f0ca5
commit c509d9897a
13 changed files with 441 additions and 5 deletions

View File

@@ -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,