4

I like the question-answer pair in this topic:

What does enctype='multipart/form-data' mean?

What I feel is missing is how does the browser / server feel the difference between a normal form post and a multipart post. Because as a user I see no difference in how the browser reacts to form submission, and as a wannabe web developer I receive the post as a whole (eg. a file), not a "part" ...

A good answer would explain what exactly is the part in multipart ?

Community
  • 1
  • 1
Xlaudius
  • 1,757
  • 2
  • 13
  • 16

1 Answers1

1

well like mentioned in your referring question, there are two ways in which encoding a post of a form could be send: application/x-www-form-urlencoded or multipart/form-data.

Both of them will be send in the body of the post request. and not like with a get where it is passed with the url itself.

Here is an example of both: http://www.htmlcodetutorial.com/forms/form_enctype.html

you could say part is the other representation of the parameter name in the urlencoded form of an get request.

urlencoded: realname= part: Content-Disposition: form-data; name="realname"

the different parts are separated by a boundary defined in the header: Content-type: multipart/form-data; boundary=---------------------------7cd1d6371ec

EDIT bedside the difference in the encoding the most importent thing is, that with multipart/form-data the client has the possibility to add additional informations to the key/value pair like the type of the value (e.g. Content-Type: image/jpeg) or the file name. With this information it is possible for the server to do certain actions for the different types of values.

When you use application/x-www-form-urlencoded it is not possible to store additional infos for a key/value pair in a standardized way.

Thats the reason why you have to use multipart/form-data if you want to submit files with the post request. It is not because it would not be possible to pass the file as a base64 encoded value in the url format, but because there is no standart way with the urlencoding to tell the server that it is a file and not a string.

t.niese
  • 39,256
  • 9
  • 74
  • 101
  • so the browser sends both of those form encodings the same way? Does no file splitting occur? I always thought that the *part* means that files are split and sent separately .. – Xlaudius Mar 07 '13 at 11:43
  • both are send in one request. the request probably could in addition be chunked encode. but it is still one request. But there does no file splitting occur the server will give you the files in one part. – t.niese Mar 07 '13 at 11:45