encoredev / encore

Development Platform for building robust type-safe distributed systems with declarative infrastructure

Home Page:https://encore.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

macleodmac opened this issue · comments

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