As per the documentation:
Warning: When using
FormData
to submitPOST
requests usingXMLHttpRequest
or theFetch_API
with the
multipart/form-data
Content-Type (e.g. when uploadingFiles
and
Blobs
to the server), do not explicitly set theContent-Type
header on the request. Doing so will prevent the browser from being
able to set theContent-Type
header with theboundary
expression
it will use to delimit form fields in the request body.
Hence, you should remove the Content-Type
header from your code when sending the fetch
request. The same applies to sending requests through Python Requests, as described here and here. Read more about the boundary in multipart/form-data.
Working examples on how to upload file(s) using FastAPI in the backend and Fetch API in the frontend can be found here, here, as well as here, here and here.