Skip to content

Content-Type: "multipart/form-data" is ignored #671

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

Closed
inomn opened this issue Dec 14, 2023 · 4 comments
Closed

Content-Type: "multipart/form-data" is ignored #671

inomn opened this issue Dec 14, 2023 · 4 comments

Comments

@inomn
Copy link

inomn commented Dec 14, 2023

In generated axios http-API client there's a line

headers: {
        ...(requestParams.headers || {}),
        ...(type && type !== ContentType.FormData ? { "Content-Type": type } : {}),
      },

this prevents us from sending a request with content-type multipart/form-data.
Could anyone tell me what the reason was for this solution?

Replacing this with a simple

      headers: {
        ...(requestParams.headers || {}),
        "Content-Type": type
      },

fixes the issue

@Isola92
Copy link

Isola92 commented Dec 19, 2023

I think the header is applied automatically by the browser when passing a FormData object in the body. Not sure if that holds true for Axios though but this appears to be the behavior for me using fetch.

@inomn
Copy link
Author

inomn commented Dec 22, 2023

@Isola92 Not the case for Axios + latest Chrome

@ThomasGuenard
Copy link

Same behavior using react-native:

We have to pass content-type with the header param to be able to send form-data.
As the generated request have already the type, it is sad to redefined it manually

@cf-dlangston
Copy link
Contributor

cf-dlangston commented Jul 15, 2024

It seems like the change adding this ...(type && type !== ContentType.FormData ? { "Content-Type": type } : {}), was part of PR #173. The rationalization in the PR being:

It's better to let the browser handle setting of this content-type, since it will add the correct boundary.

This corroborates what @Isola92 is saying. To fix I think it makes sense to remove this check from the axios-http-client.ejs template since axios doesn't automatically add this header. I just submitted MR #831 which does this.

smorimoto added a commit that referenced this issue Jul 28, 2024
Fix #671 -  Content-Type: "multipart/form-data" is ignored (when using axios)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants