Example: Multipart File Upload with cURL
curl -X POST https://files.example.com/upload \
-H 'Authorization: Bearer ***' \
-F '[email protected];type=application/pdf' \
-F 'metadata={"tag":"q3"}'
-Fbuildsmultipart/form-data(binary-safe); do not use-dfor files —--data-binary @fileworks only when the API wants raw bytes, not a form.;type=sets that part's Content-Type. Omit it and curl guesses by extension, which is fine for PDFs and catastrophic for CSVs.- Converted to Node fetch: expect a
FormData()+Blobconstruction, no manual boundary. If a converter emits a hand-builtmultipart/form-datastring with a literal boundary, that's a bug in the converter — ours isn't.
FAQ
Why is my upload corrupted when sent as raw bytes? -d @file treats content as a form-urlencoded string and will mangle binary. -F (or --form) is the multipart, binary-safe path.
Can I upload without reading the whole file into memory? curl streams from disk either way. In Node, pass a Blob backed by fs.openAsBlob() (or a File) to FormData for the same effect.
What does the converted Go code do for -F? It builds a mime.NewWriter multipart writer — see the curl-to-go route for the generated shape.