The Upload Service handles the parsing of multi-part/form-data from POST Requests, making the multi-part files available from either memory or from a specified location on the file system.
It is written for use in Turbine but it can be used in Avalon compatible container.
<role name="org.apache.fulcrum.upload.UploadService" shorthand="upload" default-class="org.apache.fulcrum.upload.DefaultUploadService"/>
Item | Datatype | Cardinality | Description |
---|---|---|---|
repository | String | [0|1] |
The directory where files will be temporarily stored (default is ".").
On Win32 file systems an entry of the form
f:\path\to\upload\repository is most likely necessary.
|
sizeMax | Integer | [0|1] | The maximum size of a request that will be processed (default is 1048576 bytes). |
sizeThreshold | Integer | [0|1] | The maximum size of a request that will have it's elements cached in memory (default is 10240 bytes). |
headerEncoding | String | [0|1] | Used to specify how the headers are encoded (default is "ISO-8859-1"). |
Create an HTML form of the type:
<form enctype="multipart/form-data" method="POST"> <input type="hidden" name="action" value="UploadExample" /> <input type="file" name="filename"> <input type="submit" value="upload" /> </form>
The Upload Service manages the storage of the FileItem in memory or at the configured repository location in the file system. It is also possible to override the repository location using the overloaded parseRequest() methods.
Typically a request would be parsed using the Fulcrum ParameterParser service, but you can achieve this manually thus:
UploadService us = (UploadService) this.lookup(UploadService.ROLE); List fileItems = us.parse(request);
FileItem provides many methods for working with the uploaded files that will function whether a file is loaded into memory or as a temporary file. All the temporary storage management and clean up occurs behind the scenes transparently to your application. FileItem objects do not span Requests, finalizers remove any temporary files created along the way.