Take the 2-minute tour ×

I want to ask a question about the multipart/form data. I find the http header of multipart post and the Content-Type: multipart/form-data; boundary=-----...---boundaryNumber. I want to ask, how many of '-' between the boundaryNumber and '='?

share|improve this question
add comment

4 Answers

up vote 12 down vote accepted

Not a single - is mandatory. You can have any number of them. It is actually a mystery to me why user-agents tend to add so many. It is probably traditional because in the old days, when people still regularly looked at the actual protocol traffic, it provided some nice visual separation. Nowadays it is pointless.

Note however, that when you use the boundary in the stream, it must be prefixed by two hyphens (--). That’s part of the protocol. Of course, the fact that most user-agents use lots of hyphens in their boundary makes this very hard to see by example.

Furthermore, the last boundary (which marks the end of the message) is prefixed and suffixed by two hyphens (--).

So in summary, you could call your boundary OMGWTFPLZDIEKTHX, and then your traffic could look like this:

Content-Type: multipart/form-data; boundary=OMGWTFPLZDIEKTHX

Content-Type: text/plain

First part (plain text).
Content-Type: text/html

<html>Second part (HTML).</html>
share|improve this answer
thank you for your reply. –  Questions Aug 18 '10 at 1:31
+1 for differentiating between the two border (--) in the spec versus the superfluous (---) that are often added to the boundary... –  LesterDove Aug 18 '10 at 1:37
What happens when you have content after the last line --OMGWTFPLZDIEKTHX-- ? –  Pacerier Jan 11 '12 at 1:47
I guess then you are violating the protocol. –  Timwi Jan 11 '12 at 21:38
It is not for people looking at protocol traffic. Multipart is also used for email, and pre-MIME email readers would show everything to the user, including the multipart boundaries. The long line of hyphens separating the parts would make things a bit more readable in that case. –  CesarB Jan 12 '12 at 17:00
show 1 more comment

It is completely arbitrary.

The point of the boundary is to define the beginning and ending of your data. It does not matter what it is, as long as it is not part of the content.

share|improve this answer
thank you for your reply. –  Questions Aug 18 '10 at 1:30
add comment

In your boundary definition, no hyphens are required. When using that boundary to separate two distinct body parts, you must start with two hyphens, followed by your previously-defined boundary string.

This is explained in RFC 1341 (MIME), and you can find additional information there in the Multipart section (as linked).

share|improve this answer
add comment

The number of dashes depends on how many you want there. It can be zero, if you like -- it's just that more dashes makes the boundary more obvious.

The boundary consists of a line containing two dashes plus everything after "boundary=". So if your header said boundary=ABC, the boundary looks like

share|improve this answer
thank you for your reply. –  Questions Aug 18 '10 at 1:29
add comment

Your Answer


