What is multipart/form-data? The line of hyphens in every upload

There is a line of text inside every file upload whose only job is to say: I am not part of the file. It looks like this — ------WebKitFormBoundary7MA4YWxkTrZu0gW — a row of hyphens and a run of random characters, sitting above your bytes and again below them.

That line is multipart/form-data, the format standardised by RFC 7578 in July 2015 and first specified in RFC 1867 in November 1995. Every file the web has ever sent — the résumé, the passport scan, the video that made the progress bar lie — travelled inside it. The design rests on one rule: the boundary delimiter must never occur inside the payload. Nothing enforces that rule. The sender picks a string long enough that the accident almost never happens, and every server downstream trusts the odds.

It is the most consequential unenforced promise in computing, and it has held for thirty years.

You can read the bet yourself. Open a browser’s developer tools, upload something, and look at the request body. Count the hyphens while you are there: the browser’s boundary begins with four, the format contributes two of its own at the front and two at the close. Everything between them is the sender’s guess at uniqueness, and the entire file-upload economy rides on that guess being right.

1995: the HTML form that could not carry a photograph

HTML forms in 1995 could send text. Names and values, joined with ampersands, percent-encoded. Ask the same form for a photograph and the arithmetic turns ugly: percent-encoding a binary blob inflates it roughly threefold, and every byte must be transformed before it can be sent.

Ernesto Nebel and Larry Masinter fixed it in RFC 1867 (November 1995), which introduced <input type="file"> and, with it, multipart/form-data. The move was elegant: stop encoding the file, wrap it. Give every field its own part, separate the parts with a delimiter, and let the browser stream bytes straight off the disk.

Masinter wrote the format up properly three years later in RFC 2388 (August 1998). Then came the revision that matters most, and it is worth noticing what kind of document RFC 7578 is. It does not invent. It takes dictation. By 2015 the format had been implemented by every browser and every server framework on earth, and the RFC was written to describe what they had already agreed to do. The specification followed the running code, not the other way round.

Anatomy of a part: Content-Disposition does the paperwork

Each part carries a Content-Disposition header where, in the specification’s words, “the disposition type is ‘form-data’”, plus “an additional parameter of ‘name’” whose value is the original field name. A file part adds a filename and its own Content-Type, so the receiver learns both what the form called the input and what the file claims to be.

The delimiter itself is “constructed using CRLF, ‘--’, and the value of the ‘boundary’ parameter”. RFC 2046, the MIME multipart specification, caps that value at seventy characters and forbids a trailing space — the entire safety margin of the world’s file uploads, expressed as a length limit.

The boundary rule: a delimiter that must not appear inside the payload

Here is the sentence the web leans on: “the boundary delimiter MUST NOT appear inside any of the encapsulated parts.”

Note what the document does with it. It states the requirement and hands the choosing to the sender. Nothing verifies the choice. No handshake confirms it. The browser generates something long and odd — WebKit’s ----WebKitFormBoundary prefix, Firefox’s wall of hyphens — and trusts the odds.

It is not a proof. It is a bet with excellent odds and no referee.

What happens when the boundary collides with the payload

When the bet loses, it loses quietly. The receiver finds the delimiter early, the part ends there, and the upload arrives truncated with no error message to announce it. A file that is merely shorter than it should be is a file most systems will happily accept, store and serve.

That is the peculiar cruelty of a probabilistic rule: its failures do not look like failures. They look like a small file, a corrupt image, a PDF that opens to a blank page — and the blame lands on the uploader, the network, or the disk.

RFC 7578: the revision that mostly removed things

The 2015 revision is largely subtraction. Content-Transfer-Encoding, inherited from mail, is deprecated here, because a part has no line-length problem to solve. The document advises restricting field names to ASCII — not because Unicode is wrong, but because the interoperability record said so. It concedes that one field name may appear many times, and that the filename a client supplies is a label, not a path.

Every one of those clauses is a scar. Behind each sits a server that guessed wrong and a browser that guessed differently.

The negotiation that never happens

There is no capability exchange. No boundary is agreed, no maximum size is declared, no version is discussed. The sender chooses, the receiver parses, and any disagreement surfaces as a rejected request or a mangled file rather than as a protocol conversation.

That is ordinary for a media type, and it is why browser behaviour became the real specification. Where the document advises, the browsers decide, and the servers learn from the browsers. A format with no negotiation has no room for argument — which is exactly why it spread.

Why multipart/form-data outlived everything around it

multipart/form-data is older than most of the web that uses it. It survived because it solved the file case with nothing but a delimiter, a header and a promise — and because replacing it means changing both ends of every connection at once.

Count the ends. Every browser ships an encoder. Every server framework ships a parser. Every web application firewall, API gateway, object-storage SDK, mobile HTTP client and logging pipeline that has ever inspected a request body has an opinion about those hyphens. A replacement would have to arrive everywhere in the same release window, and the only thing harder than shipping a new format is retiring an old one that already works.

Standards do not die of better alternatives. They die of coordinated migration, which is to say they mostly do not die.

Ask a working engineer whether they have seen a boundary collision and the answer is usually no, which is precisely the point. A format that fails once in a very long while produces no folklore, no bug-tracker pattern and no pressure to change. The absence of complaints gets read as proof of correctness.

The promise is the weak part, and it has never been weak enough to matter. Formats that run on a probabilistic assumption stay exactly where they are until a failure makes the assumption visible; this one keeps the failure rare by keeping the boundary long.

Three decades on, the web still uploads its files inside a polite lie: a string that says I am not in here, and is believed every time, because checking would cost more than the odds are worth.