views:

14

answers:

2

I read some articles on net for sending the files using HTTP/(Ajax). While reading i found stuff like need to set BOUNDARY for the file etc.

I don't understand what and why is this ? Can some one please help me understand this.

A: 

An HTTP message has only one body and that can only have one content type. That’s why there are multipart messages that are a collection of parts. And these parts are separated by a boundary. See this answer for a schematic example of how a multipart message looks like.

Gumbo
A: 

In multipart form with enctype="multipart/form-data, The client uses a boundry string that separates inputs field from the uploaded files and separation between different files. This is a string that is not present in any of the form's submitted data, including the file data. The boundry helps the server to parse data correctly to separate input fields from file data, since all the data is sent in a single request.

From rfc1867 section 3.3

A boundary is selected that does not occur in any of the data. (This selection is sometimes done probabilisticly.)

An example from the same RFC:

Suppose the server supplies the following HTML:

 <FORM ACTION="http://server.dom/cgi/handle"
       ENCTYPE="multipart/form-data"
       METHOD=POST>
 What is your name? <INPUT TYPE=TEXT NAME=submitter>
 What files are you sending? <INPUT TYPE=FILE NAME=pics>
 </FORM>

and the user types "Joe Blow" in the name field, and selects a text file "file1.txt" for the answer to 'What files are you sending?' The client might send back the following data:

    Content-type: multipart/form-data, boundary=AaB03x

    --AaB03x
    content-disposition: form-data; name="field1"

    Joe Blow
    --AaB03x
    content-disposition: form-data; name="pics"; filename="file1.txt"
    Content-Type: text/plain

     ... contents of file1.txt ...
    --AaB03x--
naikus