1001Ferramentas
📦 Dev

multipart/form-data Parser

Paste a multipart/form-data body with its boundary and inspect each part (Content-Disposition, filename, Content-Type, size).

Reading a multipart/form-data body

A form with a file uses multipart/form-data, and the resulting body is a sequence of parts separated by a marker declared in the Content-Type. Each part has headers of its own followed by its content. Paste the body and the page separates the parts, showing each one's field name, filename and declared type.

The marker has rules: it appears in the body preceded by two hyphens, and the end of the message is the marker with two hyphens at the end as well. So it must be a sequence that does not occur inside any part — if it does, the body is cut in the wrong place. That is why browsers generate long, random markers rather than something readable.

The information that drives processing comes from each part's Content-Disposition: the name parameter is the form field name, and the presence of filename is what distinguishes a file from a text field. Treat the received filename with suspicion — it comes from the client, may contain a path, and is the classic vector for writing a file outside the intended folder.

Frequently asked questions

Why not send a form with a file as JSON?
Because JSON has no binary type: the file would have to go as base64, growing by a third, and the server would have to load it all into memory to decode. Multipart allows streaming, writing the file to disk as it arrives, without inflating the size.
How does it differ from application/x-www-form-urlencoded?
urlencoded joins everything into one string of percent-encoded pairs, which suits short fields and is more compact. It has no way to carry binary without inflating it, and no per-field type. A form without files usually uses urlencoded; with files, multipart is the way.
How do accents appear in a filename?
It is the messiest part of the specification. The old form puts the name straight into filename, with no statement of encoding, and every client picked its own. The current correct form uses filename with an asterisk and a declared encoding. A robust server reads both and prefers the second where present.

Related Tools