Overview | Package | Class | Tree | Deprecated | Index | Help
| Apache Tomcat 6.0.53
PREV PACKAGE NEXT PACKAGE | FRAMES NO FRAMES

## Package org.apache.tomcat.util.http.fileupload

This is a packaged renamed copy of Apache Commons File Upload Component for handling html file uploads as given by rfc 1867 RFC 1867.

See:
Description

Interface Summary
FileItem | This class represents a file or form item that was received within a `multipart/form-data` POST request.
FileItemFactory | A factory interface for creating `FileItem` instances.

Class Summary
DefaultFileItem | The default implementation of the `FileItem` interface.
DefaultFileItemFactory | The default `FileItemFactory` implementation.
DeferredFileOutputStream | An output stream which will retain data in memory until a specified threshold is reached, and only then commit it to disk.
DiskFileUpload | High level API for processing file uploads.
FileUpload | High level API for processing file uploads.
FileUploadBase | High level API for processing file uploads.
MultipartStream | Low level API for processing file uploads.
ThresholdingOutputStream | An output stream which triggers an event when a specified number of bytes of data have been written to it.

Exception Summary
FileUploadBase.InvalidContentTypeException | Thrown to indicate that the request is not a multipart request.
FileUploadBase.SizeLimitExceededException | Thrown to indicate that the request size exceeds the configured maximum.
FileUploadBase.UnknownSizeException | Thrown to indicate that the request size is not specified.
FileUploadException | Exception for errors encountered while processing the request.

## Package org.apache.tomcat.util.http.fileupload Description

This is a packaged renamed copy of Apache Commons File Upload

Component for handling html file uploads as given by rfc 1867 RFC 1867.

Normal usage of the package involves `DiskFileUpload` parsing the HttpServletRequest and returning a list of `FileItem`'s. These `FileItem`'s provide easy access to the data given in the upload. There is also a low level api for manipulating the upload data encapsulated in the `MultipartStream` class.

Normal usage example:

        public void doPost(HttpServletRequest req, HttpServletResponse res)
        {
            DiskFileUpload fu = new DiskFileUpload();
            // maximum size before a FileUploadException will be thrown
            fu.setSizeMax(1000000);
            // maximum size that will be stored in memory
            fu.setSizeThreshold(4096);
            // the location for saving data that is larger than getSizeThreshold()
            fu.setRepositoryPath("/tmp");

            List fileItems = fu.parseRequest(req);
            // assume we know there are two files. The first file is a small
            // text file, the second is unknown and is written to a file on
            // the server
            Iterator i = fileItems.iterator();
            String comment = ((FileItem)i.next()).getString();
            FileItem fi = (FileItem)i.next();
            // filename on the client
            String fileName = fi.getName();
            // save comment and filename to database
            ...
            // write the file
            fi.write("/www/uploads/" + fileName);
        }

In the example above the first file is loaded into memory as a `String`. Before calling the getString method, the data may have been in memory or on disk depending on its size. The second file we assume it will be large and therefore never explicitly load it into memory, though if it is less than 4096 bytes it will be in memory before it is written to its final location. When writing to the final location, if the data is larger than the threshold, an attempt is made to rename the temporary file to the given location. If it cannot be renamed, it is streamed to the new location.

Overview | Package | Class | Tree | Deprecated | Index | Help
| Apache Tomcat 6.0.53
PREV PACKAGE NEXT PACKAGE | FRAMES NO FRAMES

Copyright © 2000-2017 Apache Software Foundation. All Rights Reserved.