Skip to content

JS/TS generated clients always set content-type of application/json, which makes uploading multipart/form-data difficult #1052

Closed
@macleodmac

Description

@macleodmac

When performing file uploads to raw endpoints using multipart/form-data we need to set a boundary in the Content-Type header to delineate the different parts of the request payload. fetch handles this natively for us when a FormData object is passed to it.

The auto-generated JS/TS clients are configured to set the Content-Type header to application/json for every request, without exception. Currently we can pass an overridden header for Content-Type, but that requires us to handle the boundary manually, which is not great.

Our options are to:

  1. In our overridden fetch implementation, check the type of the body and delete the application/json header if present (as it's already set at this point)
  2. Only set the application/json header if the body is not FormData, as in these cases we should allow fetch to natively handle the setting of Content-Type including boundary

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions