Make your own free website on Tripod.com

A brief explanation of how files are uploaded

by Anton Tagunov

To create a web page with file uploading capabilities you place a special form into the page, like

<FORM ACTION="/some-action" METHOD="POST" ENCTYPE="multipart/form-data">
    <INPUT TYPE="file" NAME="f">
    <INPUT TYPE="text" NAME="a">
    <INPUT TYPE="submit" VALUE="Upload">
</FORM>

And when the user choses a file and presses the Upload button then a request with special Content-Type: mutipart/form-data is submitted to the web server, something like:

POST /some-action HTTP/1.0
Content-type: multipart/form-data; boundary=---------------------------271041738421466
Content-Length: 798

-----------------------------271041738421466
Content-Disposition: form-data; name="f"; filename="the name of the file chosen"

<the-body-of-the-file-chosen>
-----------------------------271041738421466
Content-Disposition: form-data; name="a"

<value-of-the-text-input-field-named-a encoded-with-the-encoding-of-the-page-from-which-the-form-has-been-submitted>
-----------------------------271041738421466--

As you can see normal text input fields may be submetted this way in a mixture with files being uploaded.

National characters are encoded with the character encoding of the page that the form is in and this binary representation of the form fields is sent to the server without any %-ing.