Skip to content

Commit

Permalink
[Typescript-Jquery] Fix file upload (swagger-api#6262)
Browse files Browse the repository at this point in the history
* Fix a bug with the file upload that was not working

* Prevent unnecessary append to the FormData
  • Loading branch information
JFCote authored and wing328 committed Aug 9, 2017
1 parent e94ba4c commit 00b46e8
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,9 @@ export class {{classname}} {
{{#formParams}}
{{#isFile}}
reqHasFile = true;
formParams = {{paramName}};
{{/isFile}}
{{^isFile}}
{{#isListContainer}}
if ({{paramName}}) {
{{#isCollectionFormatMulti}}
Expand All @@ -121,7 +123,7 @@ export class {{classname}} {
formParams.append('{{baseName}}', <any>{{paramName}});
}
{{/isListContainer}}

{{/isFile}}
{{/formParams}}
{{#headerParams}}
{{#isListContainer}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -433,11 +433,9 @@ export class PetApi {
if (name !== null && name !== undefined) {
formParams.append('name', <any>name);
}

if (status !== null && status !== undefined) {
formParams.append('status', <any>status);
}

// to determine the Content-Type header
let consumes: string[] = [
'application/x-www-form-urlencoded'
Expand Down Expand Up @@ -515,12 +513,8 @@ export class PetApi {
if (additionalMetadata !== null && additionalMetadata !== undefined) {
formParams.append('additionalMetadata', <any>additionalMetadata);
}

reqHasFile = true;
if (file !== null && file !== undefined) {
formParams.append('file', <any>file);
}

formParams = file;
// to determine the Content-Type header
let consumes: string[] = [
'multipart/form-data'
Expand Down
8 changes: 1 addition & 7 deletions samples/client/petstore/typescript-jquery/npm/api/PetApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -433,11 +433,9 @@ export class PetApi {
if (name !== null && name !== undefined) {
formParams.append('name', <any>name);
}

if (status !== null && status !== undefined) {
formParams.append('status', <any>status);
}

// to determine the Content-Type header
let consumes: string[] = [
'application/x-www-form-urlencoded'
Expand Down Expand Up @@ -515,12 +513,8 @@ export class PetApi {
if (additionalMetadata !== null && additionalMetadata !== undefined) {
formParams.append('additionalMetadata', <any>additionalMetadata);
}

reqHasFile = true;
if (file !== null && file !== undefined) {
formParams.append('file', <any>file);
}

formParams = file;
// to determine the Content-Type header
let consumes: string[] = [
'multipart/form-data'
Expand Down

0 comments on commit 00b46e8

Please sign in to comment.