multipart/form-data multipart/form-data means: multipart/form-data is the media type for HTML form submissions that include file uploads or mixed content. Each field becomes a separate body part with its own Content-Disposition (name and optional filename) and Content-Type, all separated by a boundary token declared in the header. Multipart media types bundle several independent body parts into one message, separated by a boundary token declared in the Content-Type header. They are the backbone of HTML file uploads and mixed payloads. The boundary parameter is mandatory and must not appear inside any part, or parsers split the message at the wrong place and corrupt the upload. You will encounter multipart/form-data in contexts such as html forms with input type=file uploads; api endpoints accepting files plus metadata fields together; browser formdata submissions assembled automatically by fetch. It is commonly associated with the file extension(s) no fixed file extension. Never hand-craft the boundary: let the browser or HTTP library generate it and set the header. Each file part should carry its own Content-Type, and servers must stream-parse large uploads with size limits to avoid memory exhaustion.
When you'll see multipart/form-data
- HTML forms with input type=file uploads
- API endpoints accepting files plus metadata fields together
- Browser FormData submissions assembled automatically by fetch
How to handle it
When constructing a multipart body, let your HTTP library generate the boundary and assemble the parts — hand-rolling boundaries is error-prone. Each form-data part needs a Content-Disposition with a name, and file parts need a filename and their own Content-Type. On the server, use a streaming multipart parser to avoid buffering large uploads entirely in memory, and enforce size limits per part and per request. As a final checklist for multipart types: let libraries generate boundaries, stream-parse large uploads with per-part and per-request size limits, give each file part its own Content-Type, and reject unexpected parts early so malformed or oversized messages never exhaust server memory.
Notes & gotchas
Never hand-craft the boundary: let the browser or HTTP library generate it and set the header. Each file part should carry its own Content-Type, and servers must stream-parse large uploads with size limits to avoid memory exhaustion.
Examples
POST /v1/resource HTTP/1.1
Host: api.example.com
Content-Type: multipart/form-data; boundary=boundary123
Content-Length: 136
--boundary123
Content-Disposition: form-data; name="file"; filename="doc.txt"
Content-Type: text/plain
hello world
--boundary123-- curl -i -X POST -F "file=@doc.txt" -F "name=Ada" https://api.example.com/v1/upload # curl sets the boundary automatically const form = new FormData();
form.append("file", fileInput.files[0]);
form.append("name", "Ada");
// Do NOT set Content-Type yourself: fetch adds multipart/form-data with the boundary.
const res = await fetch("/v1/upload", { method: "POST", body: form }); import requests
with open("doc.txt", "rb") as fh:
res = requests.post("https://api.example.com/v1/upload",
files={"file": ("doc.txt", fh, "text/plain")},
data={"name": "Ada"}, timeout=30)
# requests builds multipart/form-data with a correct boundary automatically Frequently asked questions
Do I set the boundary manually in fetch?
No — when you pass a FormData body, fetch sets multipart/form-data with a generated boundary automatically. Setting the header yourself without the boundary breaks parsing.
Can multipart/form-data carry JSON fields?
Yes, as a part with Content-Type: application/json, but most APIs expect simple string fields plus file parts. Check the endpoint's contract for how it wants metadata.
Why is the boundary parameter required for multipart types?
It delimits the parts. The sender generates a unique token, declares it in Content-Type, and writes it between parts. If the token occurs inside a part's data, the parser splits incorrectly — libraries generate collision-safe boundaries for you.
What is the difference between multipart/form-data and multipart/mixed?
form-data is for HTML form submissions and file uploads (each part has a name and optional filename); mixed is a general container for unrelated parts. Browsers' FormData API produces form-data automatically with a correct boundary.
Why is my multipart upload rejected as malformed?
Usually the boundary in the Content-Type header does not match the delimiters in the body, or a part is missing its Content-Disposition. Let your HTTP library build the body so the boundary and parts stay consistent.
Try the URL Encoder
Percent-encode and decode URL components or full URLs.