cn.dreampie.upload
类 MultipartRequest

java.lang.Object
  继承者 cn.dreampie.upload.MultipartRequest

public class MultipartRequest
extends Object

A utility class to handle multipart/form-data requests, the kind of requests that support file uploads. This class emulates the interface of HttpRequest, 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.

版本:
1.0, 1998/09/18
作者:
Jason Hunter, Geoff Soutter
另请参见:
MultipartParser

字段摘要
protected  Hashtable<String,UploadedFile> files
           
protected  Hashtable<String,List<String>> params
           
 
构造方法摘要
MultipartRequest(HttpRequest request, File saveDirectory, int maxPostSize, String encoding, FileRenamer renamer, String[] allows, String[] denieds)
          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(HttpRequest request, 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(HttpRequest request, 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(HttpRequest request, String saveDirectory, int maxPostSize, FileRenamer renamer)
          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(HttpRequest request, String saveDirectory, int maxPostSize, 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(HttpRequest request, String saveDirectory, int maxPostSize, String encoding, FileRenamer renamer)
          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(HttpRequest request, String saveDirectory, 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.
 
方法摘要
 String getContentType(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.
 File getFile(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.
 Enumeration getFileNames()
          Returns the names of all the uploaded files as an Enumeration of Strings.
 Hashtable<String,UploadedFile> getFiles()
          Returns all File objects for the specified file saved on the server's filesystem
 String getFilesystemName(String name)
          Returns the filesystem name of the specified file, or null if the file was not included in the upload.
 String getOriginalFileName(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.
 Hashtable<String,List<String>> getParams()
          Returns all Param objects for the specified param saved on the server's filesystem
 
从类 java.lang.Object 继承的方法
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

字段详细信息

params

protected Hashtable<String,List<String>> params

files

protected Hashtable<String,UploadedFile> files
构造方法详细信息

MultipartRequest

public MultipartRequest(HttpRequest request,
                        String saveDirectory)
                 throws IOException
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. If the content is too large, an IOException is thrown. This constructor actually parses the multipart/form-data and throws an IOException if there's any problem reading or parsing the request.

参数:
request - the servlet request.
saveDirectory - the directory in which to save any uploaded files.
抛出:
IOException - if the uploaded content is larger than 1 Megabyte or there's a problem reading or parsing the request.

MultipartRequest

public MultipartRequest(HttpRequest request,
                        String saveDirectory,
                        int maxPostSize)
                 throws IOException
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. If the content is too large, an IOException is thrown. This constructor actually parses the multipart/form-data and throws an IOException if there's any problem reading or parsing the request.

参数:
request - the servlet request.
saveDirectory - the directory in which to save any uploaded files.
maxPostSize - the maximum size of the POST content.
抛出:
IOException - if the uploaded content is larger than maxPostSize or there's a problem reading or parsing the request.

MultipartRequest

public MultipartRequest(HttpRequest request,
                        String saveDirectory,
                        String encoding)
                 throws IOException
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. If the content is too large, an IOException is thrown. This constructor actually parses the multipart/form-data and throws an IOException if there's any problem reading or parsing the request.

参数:
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
抛出:
IOException - if the uploaded content is larger than 1 Megabyte or there's a problem reading or parsing the request.

MultipartRequest

public MultipartRequest(HttpRequest request,
                        String saveDirectory,
                        int maxPostSize,
                        FileRenamer renamer)
                 throws IOException
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. If the content is too large, an IOException is thrown. This constructor actually parses the multipart/form-data and throws an IOException if there's any problem reading or parsing the request.

参数:
request - the servlet request.
saveDirectory - the directory in which to save any uploaded files.
maxPostSize - the maximum size of the POST content.
renamer - change file name
抛出:
IOException - if the uploaded content is larger than maxPostSize or there's a problem reading or parsing the request.

MultipartRequest

public MultipartRequest(HttpRequest request,
                        String saveDirectory,
                        int maxPostSize,
                        String encoding)
                 throws IOException
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. If the content is too large, an IOException is thrown. This constructor actually parses the multipart/form-data and throws an IOException if there's any problem reading or parsing the request.

参数:
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
抛出:
IOException - if the uploaded content is larger than maxPostSize or there's a problem reading or parsing the request.

MultipartRequest

public MultipartRequest(HttpRequest request,
                        String saveDirectory,
                        int maxPostSize,
                        String encoding,
                        FileRenamer renamer)
                 throws IOException
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. If the content is too large, an IOException is thrown. This constructor actually parses the multipart/form-data and throws an IOException if there's any problem reading or parsing the request.

To avoid file collisions, this constructor takes an implementation of the FileRenamePolicy interface to allow a pluggable rename policy.

参数:
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
renamer - a pluggable file rename policy
抛出:
IOException - if the uploaded content is larger than maxPostSize or there's a problem reading or parsing the request.

MultipartRequest

public MultipartRequest(HttpRequest request,
                        File saveDirectory,
                        int maxPostSize,
                        String encoding,
                        FileRenamer renamer,
                        String[] allows,
                        String[] denieds)
                 throws IOException
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. If the content is too large, an IOException is thrown. This constructor actually parses the multipart/form-data and throws an IOException if there's any problem reading or parsing the request.

To avoid file collisions, this constructor takes an implementation of the FileRenamePolicy interface to allow a pluggable rename renamer.

参数:
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
renamer - a pluggable file rename renamer
抛出:
IOException - if the uploaded content is larger than maxPostSize or there's a problem reading or parsing the request.
方法详细信息

getFileNames

public Enumeration getFileNames()
Returns the names of all the uploaded files as an Enumeration of Strings. It returns an empty Enumeration if there are no uploaded files. Each file name is the name specified by the form, not by the user.

返回:
the names of all the uploaded files as an Enumeration of Strings.

getFilesystemName

public String getFilesystemName(String name)
Returns the filesystem name of the specified file, or null if the file was not included in the upload. A filesystem name is the name specified by the user. It is also the name under which the file is actually saved.

参数:
name - the file name.
返回:
the filesystem name of the file.

getOriginalFileName

public String getOriginalFileName(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. A filesystem name is the name specified by the user.

参数:
name - the file name.
返回:
the original file name of the file.

getContentType

public String getContentType(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.

参数:
name - the file name.
返回:
the content type of the file.

getFile

public File getFile(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.

参数:
name - the file name.
返回:
a File object for the named file.

getFiles

public Hashtable<String,UploadedFile> getFiles()
Returns all File objects for the specified file saved on the server's filesystem

返回:
a File objects.

getParams

public Hashtable<String,List<String>> getParams()
Returns all Param objects for the specified param saved on the server's filesystem

返回:
a Param objects.


Copyright © 2015. All rights reserved.