Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeScript Fetch client doesn't support multipart/form-data body #3921

Open
janslow opened this issue Oct 4, 2016 · 6 comments
Open

TypeScript Fetch client doesn't support multipart/form-data body #3921

janslow opened this issue Oct 4, 2016 · 6 comments

Comments

@janslow
Copy link

janslow commented Oct 4, 2016

Description

If a POST operation accepts multipart/form-data, the typescript-fetch client posts an application/x-www-form-urlencoded body instead of form data.

Swagger-codegen version

Version currently deployed on [editor.swagger.io]

Swagger declaration file content or url
swagger: '2.0'
info: { version: 0.1.0, title: Multipart Upload }
paths:
  /:
    post:
      operationId: upload
      consumes:
        - multipart/form-data
      parameters:
        - name: file
          in: formData
          required: true
          type: file
      responses: { '200': { description: Successful upload } }
Command line used for generation

"Generate Client" -> "TypeScript Fetch" on [editor.swagger.io]

Steps to reproduce
  1. Generate and compile the sample config
  2. Call it with a file
  3. Log the request, it has a Content-Type of application/x-www-form-urlencoded instead of multipart/form-data.
Suggest a Fix

Instead of setting the Content-Type and using querystring to serialize the contents (for multipart/form-data requests), it should just set the body to an instance of FormData instead of

e.g., in DefaultApiFetchParamCreactor#upload, instead of :

let contentTypeHeader: Dictionary<string>;
contentTypeHeader = { "Content-Type": "application/x-www-form-urlencoded" };
fetchOptions.body = querystring.stringify({ 
  "file": params.file,
});
if (contentTypeHeader) {
  fetchOptions.headers = contentTypeHeader;
}

it should generate (as Content-Type is set to multipart/form-data automatically if using FormData):

const formData = new FormData();
formData.append("file", params.file);
fetchOptions.body = formData;
@wing328
Copy link
Contributor

wing328 commented Feb 15, 2017

@janslow thanks for reporting the issue. May I know if you've time to contribute the fix?

@wing328 wing328 modified the milestones: v2.2.2, Future Feb 15, 2017
@russtacular
Copy link

@wing328 I actually ran into the same issue myself and was in the process of putting together a PR for this and #4153

I can try to pull something together in the next few days, if that's useful for you and @janslow

@bvwells
Copy link
Contributor

bvwells commented Mar 12, 2018

Just wondering whether there is any update with this issue?

@Alexuy
Copy link

Alexuy commented Jun 27, 2018

Hey, guys! What about this issue? When you planning to fix that bug?

@wing328 @russtacular

@Splash34
Copy link

Splash34 commented Feb 7, 2020

+1

@ds1371dani
Copy link

Any news on a fix?

currently we can't use any endpoint which uploads a file because of this 😢 .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants