public class FileUpload extends Object
High level API for processing file uploads.
This class handles multiple files per single HTML widget, sent using multipart/mixed encoding type, as specified by
RFC 1867.
How the data for individual parts is stored is determined by the factory used to create them; a given part may be in memory, on disk, or somewhere else.
| 限定符和类型 | 类和说明 |
|---|---|
class |
FileUpload.FileItemIteratorImpl
The iterator, which is returned by
getItemIterator(HttpServletRequest). |
| 限定符和类型 | 字段和说明 |
|---|---|
static String |
ATTACHMENT
Content-disposition value for file attachment.
|
static String |
CONTENT_DISPOSITION
HTTP content disposition header name.
|
static String |
CONTENT_LENGTH
HTTP content length header name.
|
static String |
CONTENT_TYPE
HTTP content type header name.
|
static String |
FORM_DATA
Content-disposition value for form data.
|
static String |
MULTIPART
Part of HTTP content type header.
|
static String |
MULTIPART_FORM_DATA
HTTP content type header for multipart forms.
|
static String |
MULTIPART_MIXED
HTTP content type header for multiple uploads.
|
| 构造器和说明 |
|---|
FileUpload() |
FileUpload(Settings settings) |
| 限定符和类型 | 方法和说明 |
|---|---|
protected byte[] |
getBoundary(String contentType)
Retrieves the boundary from the
Content-type header. |
protected String |
getFieldName(FileItemHeaders headers)
Retrieves the field name from the
Content-disposition header. |
protected String |
getFileName(FileItemHeaders headers)
Retrieves the file name from the
Content-disposition header. |
long |
getFileSizeMax()
Returns the maximum allowed size of a single uploaded file, as opposed to
getSizeMax(). |
String |
getHeaderEncoding()
Retrieves the character encoding used when reading the headers of an individual part.
|
Iterator<FileItemStream> |
getItemIterator(javax.servlet.http.HttpServletRequest request)
Processes an RFC 1867 compliant
multipart/form-data stream. |
protected FileItemHeaders |
getParsedHeaders(String headerPart)
Parses the
header-part and returns as key/value pairs. |
long |
getSizeMax()
Returns the maximum allowed size of a complete request, as opposed to
getFileSizeMax(). |
static boolean |
isMultipartContent(javax.servlet.http.HttpServletRequest request)
Utility method that determines whether the request contains multipart content.
|
List<FileItem> |
parseRequest(javax.servlet.http.HttpServletRequest request,
FileItemFactory factory)
Processes an RFC 1867 compliant
multipart/form-data stream. |
void |
setFileSizeMax(long fileSizeMax)
Sets the maximum allowed size of a single uploaded file, as opposed to
getSizeMax(). |
void |
setHeaderEncoding(String encoding)
Specifies the character encoding to be used when reading the headers of individual part.
|
void |
setSizeMax(long sizeMax)
Sets the maximum allowed size of a complete request, as opposed to
setFileSizeMax(long). |
public static final String CONTENT_DISPOSITION
public static final String CONTENT_LENGTH
public static final String ATTACHMENT
public static final String MULTIPART_FORM_DATA
public FileUpload()
public FileUpload(Settings settings)
public static final boolean isMultipartContent(javax.servlet.http.HttpServletRequest request)
request - The servlet request to be evaluated. Must be non-null.true if the request is multipart;
false otherwise.public long getSizeMax()
getFileSizeMax().setSizeMax(long)public void setSizeMax(long sizeMax)
setFileSizeMax(long).sizeMax - The maximum allowed size, in bytes. The default value of -1 indicates, that there is no limit.getSizeMax()public long getFileSizeMax()
getSizeMax().setFileSizeMax(long)public void setFileSizeMax(long fileSizeMax)
getSizeMax().fileSizeMax - Maximum size of a single uploaded file.getFileSizeMax()public String getHeaderEncoding()
null, the request encoding is used.
If that is also not specified, or null, the platform default encoding is used.public void setHeaderEncoding(String encoding)
null, the request encoding is used.
If that is also not specified, or null, the platform default encoding is used.encoding - The encoding used to read part headers.public Iterator<FileItemStream> getItemIterator(javax.servlet.http.HttpServletRequest request) throws IOException
multipart/form-data stream.request - The request.FileItemStream
parsed from the request, in the order that they were transmitted.FileUploadException - if there are problems reading/parsing the request or storing files.IOException - An I/O error occurred. This may be a network
error while communicating with the client or a problem while storing the uploaded content.public List<FileItem> parseRequest(javax.servlet.http.HttpServletRequest request, FileItemFactory factory) throws IOException
multipart/form-data stream.request - the request.FileItem instances parsed from the request, in the order that they were transmitted.FileUploadException - if there are problems reading/parsing the request or storing files.IOExceptionprotected byte[] getBoundary(String contentType)
Content-type header.contentType - The value of the content type header from which to extract the boundary value.protected String getFileName(FileItemHeaders headers)
Content-disposition header.headers - The HTTP headers object.encapsulation.protected String getFieldName(FileItemHeaders headers)
Content-disposition header.headers - A Map containing the HTTP request headers.encapsulation.protected FileItemHeaders getParsedHeaders(String headerPart)
Parses the header-part and returns as key/value pairs.
If there are multiple headers of the same names, the name will map to a comma-separated list containing the values.
headerPart - The header-part of the current
encapsulation.Map containing the parsed HTTP request headers.Copyright © 2020. All rights reserved.