|
FileUpload has two main points of interest to a user: the class org.apache.commons.fileupload.DiskFileUpload, which parses the incoming data, and the interface org.apache.commons.fileupload.FileItem, returned when the file upload data has successfully been parsed. The class hierarchy for DiskFileUpload is shown in Figure 2-4. Figure 2-4. DiskFileUpload class.To use DiskFileUpload, the application needs to set a temporary path on disk to spool file data and the size threshold. It's easy to envision applications that might require several megabytes to be uploaded at a time, and by using the DiskFileUpload class with appropriate thresholds, the application will try not to overload the server.
The main DiskFileUpload method of interest is parseRequest(). It returns a List of FileItem objects , shown in more detail in Figure 2-5. Figure 2-5. FileItem class.
The bulk of the methods of the FileItem interface are fairly self-explanatory. The most significant thing to be aware of is that using get() will load the entire file into memory at once, whereas getInputStream() allows for buffering and other stream operations. |
|