Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the '-' in multipart/form-data?

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 '='?

like image 989
Questions Avatar asked Aug 18 '10 01:08

Questions


People also ask

What does Enctype =' multipart form data mean?

enctype='multipart/form-data' means that no characters will be encoded. that is why this type is used while uploading files to server. So multipart/form-data is used when a form requires binary data, like the contents of a file, to be uploaded.

What is the format of multipart form data?

A multipart formpost is what an HTTP client sends when an HTML form is submitted with enctype set to "multipart/form-data". It is an HTTP POST request sent with the request body specially formatted as a series of "parts", separated with MIME boundaries.

What does Enctype mean?

enctype property is the MIME type of content that is used to submit the form to the server. Possible values are: application/x-www-form-urlencoded : The initial default type. multipart/form-data : The type that allows file <input> element(s) to upload file data.

How does multipart form data work?

Multipart/form-data is one of the most used enctype/content type. In multipart, each of the field to be sent has its content type, file name and data separated by boundary from other field. No encoding of the data is necessary, because of the unique boundary. The binary data is sent as it is.


2 Answers

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

--OMGWTFPLZDIEKTHX
Content-Type: text/plain

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

<html>Second part (HTML).</html>
--OMGWTFPLZDIEKTHX--
like image 86
Timwi Avatar answered Oct 06 '22 00:10

Timwi


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

--ABC
like image 35
cHao Avatar answered Oct 06 '22 00:10

cHao