RFC 1867 - Form-based File Upload in HTML

This section describes the file upload specification, 'RFC 1867 - Form-based File Upload in HTML', proposed by E. Nebel and L. Masinter in 1995.

To set up a Web page for users to upload files, you need to:

Let's look at the specification first. In order to upload files to Web servers, RFC 1867 - Form-based File Upload in HTML was proposed by E. Nebel and L. Masinter in 1995. It offers:

1. A new type code, FILE, for the INPUT HTML tag:

   <INPUT TYPE="FILE" NAME="field_name" VALUE="file_name">

A Web browser should interpret this tag as an input field to enter a file name on the local system. Some browsers, like Internet Explorer, will also display button called "Browse" next to this field to allow users to browse the local file system to select a file name.

2. A new encryption type code, multipart/form-date, for the FORM HTML tag:

   <FORM ACTION="url" METHOD="post" ENCTYPE="multipart/form-data">

When a user clicks the submit button on Web form with this tag, the Web browser should collect data from all input fields and submit to the specified URL. The browser should also follow the following rules:

When "multipart/form-data" is specified as the encryption type, the format of the HTTP request body should look like this:

--boundary_identification_string
input_part_1
--boundary_identification_string
input_part_2
--boundary_identification_string
input_part_3
......
--boundary_identification_string--

The format of each input part is depending on the input field type. For any types other than FILE, the format should look like this:

Content-Disposition: form-data; name="field_name"

field_value

For an input field of type FILE, the format of the input part should look like this:

Content-Disposition: form-data; name="field_name"; filename="file_name"
Content-Type: file_type

file_content

Here is sample HTML page to show you how to use FILE input field and "multipart/form-data" encryption type:

<?xml version="1.0"?>
<html><body>
<!-- UploadSample.html
     Copyright (c) 2004 by Dr. Herong Yang
-->
<form action="some_url" enctype="multipart/form-data" method="post">
<input type="text" name="author" value="Herong Yang"/>
<input type="file" name="picture" value="C:\dot.gif"/>
<input type="submit" name="submit" value="Submit"/>
</form>
</body></html>

The browser should submit the following multiple-part HTTP request body when users click the submit button:

--boundary_identification_string
Content-Disposition: form-data; name="author"

Herong Yang
--boundary_identification_string
Content-Disposition: form-data; name="picture"; filename="C:\dot.gif"
Content-Type: image/gif

dot.gif_file_content
--boundary_identification_string
Content-Disposition: form-data; name="submit"

Submit
--boundary_identification_string--

Last update: 2012.

Table of Contents

 About This Book

 JSP (JavaServer Pages) Overview

 Tomcat 7 Installation on Windows Systems

 JSP Scripting Elements

 Java Servlet Introduction

 JSP Implicit Objects

 Syntax of JSP Pages and JSP Documents

 JSP Application Session

 Managing Cookies in JSP Pages

 JavaBean Objects and "useBean" Action Elements

 Managing HTTP Response Header Lines

 Non-ASCII Characters Support in JSP Pages

 Performance of JSP Pages

 EL (Expression Language)

 Overview of JSTL (JSP Standard Tag Libraries)

 JSTL Core Library

 JSP Custom Tags

 JSP Java Tag Interface

 Custom Tag Attributes

 Multiple Tags Working Together

File Upload Test Application

RFC 1867 - Form-based File Upload in HTML

 Code 1 - Display Options - UploadInit.html

 Code 2 - Display Form - UploadForm.jspx

 Code 3 - Dump File - UploadDump.jspx

 Test 1 - GET Method - Failed

 Test 2 - POST Method - Successful

 Code 4 - Save File - UploadSave.jspx

 Test 3 - Save File - Successful

 Code Review - UploadSave.jspx

 Outdated Tutorials

 References

 PDF Printing Version