org.dbforms.util
Class MultipartRequest

java.lang.Object
  extended by org.dbforms.util.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 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) or internationalized content (such as non Latin-1 filenames).

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 .

PLEASE NOTE: this class uses Multipart Support Classes by Jason Hunter. Copyright (C) 1998 by Jason Hunter. All rights reserved. Use of this class is limited. Please see the LICENSE for more information. Make sure that you project meets the requierements defined by Jason Hunter respective O'reilly!

Author:
Jason Hunter, Geoff Soutter, Joe Peer - _changed_ it for use in DbForms (i apologize)
See Also:
MultipartParser

Constructor Summary
MultipartRequest(HttpServletRequest request, 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.
 
Method Summary
 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.
 FileHolder getFileHolder(String name)
          Returns a FilePart object for the specified file this method was added by joe peer
 InputStream getFileInputStream(String name)
          Returns a InputStream 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.
 String getFilesystemName(String name)
          Returns the filesystem name of the specified file, or null if the file was not included in the upload.
 String getParameter(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.
 Enumeration getParameterNames()
          Returns the names of all the parameters as an Enumeration of Strings.
 String[] getParameterValues(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
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MultipartRequest

public MultipartRequest(HttpServletRequest request,
                        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.

Parameters:
request - the servlet request.
maxPostSize - the maximum size of the POST content.
Throws:
IOException - if the uploaded content is larger than maxPostSize or there's a problem reading or parsing the request.
Method Detail

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.

Parameters:
name - the file name.
Returns:
the content type of the file.

getFileHolder

public FileHolder getFileHolder(String name)
Returns a FilePart object for the specified file this method was added by joe peer

Parameters:
name - the file name.
Returns:
a FilePart object for the named file.

getFileInputStream

public InputStream getFileInputStream(String name)
Returns a InputStream object for the specified file saved on the server's filesystem, or null if the file was not included in the upload.

Parameters:
name - the file name.
Returns:
a InputStream object for the named file.

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.

Returns:
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.

Parameters:
name - the file name.
Returns:
the filesystem name of the file.

getParameter

public String getParameter(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. The value is guaranteed to be in its normal, decoded form. If the parameter has multiple values, only the last one is returned (for backward compatibility). For parameters with multiple values, it's possible the last "value" may be null.

Parameters:
name - the parameter name.
Returns:
the parameter value.

getParameterNames

public Enumeration getParameterNames()
Returns the names of all the parameters as an Enumeration of Strings. It returns an empty Enumeration if there are no parameters.

Returns:
the names of all the parameters as an Enumeration of Strings.

getParameterValues

public String[] getParameterValues(String name)
Returns the values of the named parameter as a String array, or null if the parameter was not sent. The array has one entry for each parameter field sent. If any field was sent without a value that entry is stored in the array as a null. The values are guaranteed to be in their normal, decoded form. A single value is returned as a one-element array.

Parameters:
name - the parameter name.
Returns:
the parameter values.


Copyright © 2002-2006 DbForms. All Rights Reserved.