FileItem | This class represents a file or form item that was received within a
|
code | html |
FileItemFactory | A factory interface for creating FileItem instances. |
code | html |
FileUploadBase | High level API for processing file uploads. This class handles multiple files per single HTML widget, sent using
|
code | html |
ThresholdingOutputStream | An output stream which triggers an event when a specified number of bytes of data have been written to it. | code | html |
DefaultFileItem | The default implementation of the FileItem interface. |
code | html |
DefaultFileItemFactory | The default org.apache.tomcat.util.http.fileupload.FileItemFactory implementation. |
code | html |
DeferredFileOutputStream | An output stream which will retain data in memory until a specified threshold is reached, and only then commit it to disk. |
code | html |
DiskFileUpload | High level API for processing file uploads. This class handles multiple files per single HTML widget, sent using
|
code | html |
FileUpload | High level API for processing file uploads. This class handles multiple files per single HTML widget, sent using
|
code | html |
FileUploadBase.InvalidContentTypeException | Thrown to indicate that the request is not a multipart request. | code | html |
FileUploadBase.SizeLimitExceededException | Thrown to indicate that the request size exceeds the configured maximum. | code | html |
FileUploadBase.UnknownSizeException | Thrown to indicate that the request size is not specified. | code | html |
FileUploadException | Exception for errors encountered while processing the request. | code | html |
MultipartStream | Low level API for processing file uploads. |
code | html |
MultipartStream.IllegalBoundaryException | Thrown upon attempt of setting an invalid boundary token. | code | html |
MultipartStream.MalformedStreamException | Thrown to indicate that the input stream fails to follow the required syntax. | code | html |
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.