|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.oreilly.servlet.MultipartRequest
public class MultipartRequest
A utility class to handle multipart/form-data
requests,
the kind of requests that support file uploads. This class emulates the
interface of HttpServletRequest
, making it familiar to use.
It uses a "push" model where any incoming files are read and saved directly
to disk in the constructor. If you wish to have more flexibility, e.g.
write the files to a database, use the "pull" model
MultipartParser
instead.
This class can receive arbitrarily large files (up to an artificial limit you can set), and fairly efficiently too. It cannot handle nested data (multipart content within multipart content). It can now with the latest release handle internationalized content (such as non Latin-1 filenames).
To avoid collisions and have fine control over file placement, there's a constructor variety that takes a pluggable FileRenamePolicy implementation. A particular policy can choose to rename or change the location of the file before it's written.
See the included upload.war for an example of how to use this class.
The full file upload specification is contained in experimental RFC 1867, available at http://www.ietf.org/rfc/rfc1867.txt.
MultipartParser
Constructor Summary | |
---|---|
MultipartRequest(HttpServletRequest request,
java.lang.String saveDirectory)
Constructs a new MultipartRequest to handle the specified request, saving any uploaded files to the given directory, and limiting the upload size to 1 Megabyte. |
|
MultipartRequest(HttpServletRequest request,
java.lang.String saveDirectory,
int maxPostSize)
Constructs a new MultipartRequest to handle the specified request, saving any uploaded files to the given directory, and limiting the upload size to the specified length. |
|
MultipartRequest(HttpServletRequest request,
java.lang.String saveDirectory,
int maxPostSize,
FileRenamePolicy policy)
Constructs a new MultipartRequest to handle the specified request, saving any uploaded files to the given directory, and limiting the upload size to the specified length. |
|
MultipartRequest(HttpServletRequest request,
java.lang.String saveDirectory,
int maxPostSize,
java.lang.String encoding)
Constructs a new MultipartRequest to handle the specified request, saving any uploaded files to the given directory, and limiting the upload size to the specified length. |
|
MultipartRequest(HttpServletRequest request,
java.lang.String saveDirectory,
int maxPostSize,
java.lang.String encoding,
FileRenamePolicy policy)
Constructs a new MultipartRequest to handle the specified request, saving any uploaded files to the given directory, and limiting the upload size to the specified length. |
|
MultipartRequest(HttpServletRequest request,
java.lang.String saveDirectory,
java.lang.String encoding)
Constructs a new MultipartRequest to handle the specified request, saving any uploaded files to the given directory, and limiting the upload size to the specified length. |
Method Summary | |
---|---|
java.lang.String |
getContentType(java.lang.String name)
Returns the content type of the specified file (as supplied by the client browser), or null if the file was not included in the upload. |
java.io.File |
getFile(java.lang.String name)
Returns a File object for the specified file saved on the server's filesystem, or null if the file was not included in the upload. |
java.util.Enumeration |
getFileNames()
Returns the names of all the uploaded files as an Enumeration of Strings. |
java.lang.String |
getFilesystemName(java.lang.String name)
Returns the filesystem name of the specified file, or null if the file was not included in the upload. |
java.lang.String |
getOriginalFileName(java.lang.String name)
Returns the original filesystem name of the specified file (before any renaming policy was applied), or null if the file was not included in the upload. |
java.lang.String |
getParameter(java.lang.String name)
Returns the value of the named parameter as a String, or null if the parameter was not sent or was sent without a value. |
java.util.Enumeration |
getParameterNames()
Returns the names of all the parameters as an Enumeration of Strings. |
java.lang.String[] |
getParameterValues(java.lang.String name)
Returns the values of the named parameter as a String array, or null if the parameter was not sent. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public MultipartRequest(HttpServletRequest request, java.lang.String saveDirectory) throws java.io.IOException
request
- the servlet request.saveDirectory
- the directory in which to save any uploaded files.
java.io.IOException
- if the uploaded content is larger than 1 Megabyte
or there's a problem reading or parsing the request.public MultipartRequest(HttpServletRequest request, java.lang.String saveDirectory, int maxPostSize) throws java.io.IOException
request
- the servlet request.saveDirectory
- the directory in which to save any uploaded files.maxPostSize
- the maximum size of the POST content.
java.io.IOException
- if the uploaded content is larger than
maxPostSize or there's a problem reading or parsing the request.public MultipartRequest(HttpServletRequest request, java.lang.String saveDirectory, java.lang.String encoding) throws java.io.IOException
request
- the servlet request.saveDirectory
- the directory in which to save any uploaded files.encoding
- the encoding of the response, such as ISO-8859-1
java.io.IOException
- if the uploaded content is larger than
1 Megabyte or there's a problem reading or parsing the request.public MultipartRequest(HttpServletRequest request, java.lang.String saveDirectory, int maxPostSize, FileRenamePolicy policy) throws java.io.IOException
request
- the servlet request.saveDirectory
- the directory in which to save any uploaded files.maxPostSize
- the maximum size of the POST content.encoding
- the encoding of the response, such as ISO-8859-1
java.io.IOException
- if the uploaded content is larger than
maxPostSize or there's a problem reading or parsing the request.public MultipartRequest(HttpServletRequest request, java.lang.String saveDirectory, int maxPostSize, java.lang.String encoding) throws java.io.IOException
request
- the servlet request.saveDirectory
- the directory in which to save any uploaded files.maxPostSize
- the maximum size of the POST content.encoding
- the encoding of the response, such as ISO-8859-1
java.io.IOException
- if the uploaded content is larger than
maxPostSize or there's a problem reading or parsing the request.public MultipartRequest(HttpServletRequest request, java.lang.String saveDirectory, int maxPostSize, java.lang.String encoding, FileRenamePolicy policy) throws java.io.IOException
request
- the servlet request.saveDirectory
- the directory in which to save any uploaded files.maxPostSize
- the maximum size of the POST content.encoding
- the encoding of the response, such as ISO-8859-1policy
- a pluggable file rename policy
java.io.IOException
- if the uploaded content is larger than
maxPostSize or there's a problem reading or parsing the request.Method Detail |
---|
public java.util.Enumeration getParameterNames()
public java.util.Enumeration getFileNames()
public java.lang.String getParameter(java.lang.String name)
name
- the parameter name.
public java.lang.String[] getParameterValues(java.lang.String name)
name
- the parameter name.
public java.lang.String getFilesystemName(java.lang.String name)
name
- the file name.
public java.lang.String getOriginalFileName(java.lang.String name)
name
- the file name.
public java.lang.String getContentType(java.lang.String name)
name
- the file name.
public java.io.File getFile(java.lang.String name)
name
- the file name.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |