swagger-typescript-api icon indicating copy to clipboard operation
swagger-typescript-api copied to clipboard

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

Open inomn opened this issue 1 year ago • 3 comments
trafficstars

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

inomn avatar Dec 14 '23 09:12 inomn

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.

Isola92 avatar Dec 19 '23 10:12 Isola92

@Isola92 Not the case for Axios + latest Chrome

inomn avatar Dec 22 '23 10:12 inomn

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

ThomasGuenard avatar Jan 03 '24 14:01 ThomasGuenard