multipart/form-data
The request format that lets one form send files and ordinary fields together without turning the file into base64 JSON.
See it
What it is
multipart/form-data is an HTTP body format that packages several parts into one request. Each part has its own headers and content, so a form can send a binary file beside ordinary fields such as title or userId. A boundary marker separates the parts, following the format defined by RFC 7578.
Use it for a modest file upload that must travel with related form values. It is what a plain HTML form switches to when you set enctype=multipart/form-data on the form tag. In a browser, append File and string values to the FormData API and pass that object to fetch. The browser writes the multipart body and chooses a boundary, which is much more efficient than stuffing binary data into base64 JSON.
The famous gotcha is setting Content-Type yourself. If you leave out the generated boundary, the server cannot split the parts; let the browser set the header. On the server, stream large files instead of buffering the whole body, enforce byte and part-count limits, and treat the filename and claimed media type as untrusted input.
Ask AI for it
Implement POST /api/uploads with the browser FormData API and @fastify/multipart. Append the File under 'file' and the caption under 'caption', pass the FormData directly to fetch, and do not set the Content-Type header in browser code. On Fastify, stream the file to storage, cap it at 10 MB, allow only JPEG and PNG after inspecting its magic bytes, reject extra file parts, generate the storage key server-side, and return an RFC 9457 error body for invalid uploads.