Media type · multipart/form-data

multipart/form-data

multipart/form-data is the media type for forms that include files or binary fields.

Key facts

Typemultipart/form-data
ExtensionsNone
StandardRFC 7578; RFC 2046
Text or binaryMixed
Required parameterboundary

What it is

It encodes a form as a sequence of parts, each with its own headers and content. A unique boundary string separates the parts; because the boundary must not appear in the data, the client generates a value unlikely to collide. File uploads use this type because a text-only encoding would corrupt binary bytes.

Why uploads fail

Hand-built bodies often use a boundary that does not match the header, omit the final --boundary-- terminator, or set the wrong Content-Type on a part. Let the browser or HTTP client build the body: in fetch, pass a FormData object and do not set the Content-Type header yourself, because the client must add the boundary.

Frequently asked questions

Why should I not set Content-Type for FormData?

The browser must add the boundary parameter. Setting the header manually usually omits it, so the server cannot parse the parts.

Is multipart/form-data only for files?

No. It handles ordinary fields too, but for text-only forms application/x-www-form-urlencoded is smaller and simpler.

New tools, straight to your inbox

One short email when we add tools worth using. No spam, unsubscribe anytime.