http.utils.multipartrequest
Class MultipartRequest

java.lang.Object
  extended byhttp.utils.multipartrequest.MultipartRequest
Direct Known Subclasses:
CgiMultipartRequest, ServletMultipartRequest

public class MultipartRequest
extends java.lang.Object

A Multipart form data parser. Parses an input stream and writes out any files found, making available a hashtable of other url parameters. As of version 1.17 the files can be saved to memory, and optionally written to a database, etc.

Copyright (c)2001-2003 Jason Pell.

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) any later version.
    
This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Email: jasonpell@hotmail.com Url: http://www.geocities.com/jasonpell

Version:
1.30rc1- Updated the getFileContent() method to return an instance of EmptyInputStream, where a filename was provided in the upload process, but the file was empty. - Updated trimQuotes(...) method to fix bug #693432, 1.30b4 - Minor fixes to setEncoding(String enc), thanks to Rob Gaunt & ZiP (zip_dev) - Fix to readAndWriteFile(...) method to ensure the out file is always closed, even if an exception occurs, thanks to David Thompson. - Revise some of the changes made in 1.3-jspWiki, 1.3-jspWiki 2003-01-07, Torsten Hildebrandt (THildebrandt@gmx.de) Fixes - TempFile.createTempFile() caused an endless loop on Windows if filename is a URL with Parameters. - using fixed scheme for temporary file-names now ("multPartReq"".tmp"). Old scheme not only triggered the endless loop above, but also throws an exception with short filenames (like "ab.txt"). Enhancements - Encoding can be specified for each object independently. - method getRawFilename() added, that returns the filename exactly as transmitted by the browser, 1.30b2 A minor fix to readAndWriteFile(...) method. We need to check for whether 'out' object is null before trying to call the close method., 1.30b1 Added functionality to save uploaded files under a temporary file name. I 'borrowed' the TempFile class functionality from Java 2 java.io.File to ensure that this class is still compatible with JDK 1.1.x. I also modified some of the string comparisons ('Content-Type') to be case-insensitive, just in case some idiot decides to write a browser which does not initcap the Content and the Type words., 1.21 A minor fix for IE4 on Mac which added extra newline after last boundary. This 'fooled' previous versions of MultipartRequest into thinking another block was present., 1.20 A very minor fix, but one apparently that was causing some serious issues for some users. The intTotalRead integer was being set to -1, which meant that it was always off by one when comparing to Content-Length. Thanks to David Tuma for this fix. 19/10/2001, 1.19 Moved the MultipartRequest into a package, and thus into a java archive for easier dissemination. Fixed a bug, where in netscape if a file was uploaded with an unrecognised extension, no Content-Type was specified, so the first line of the file was chopped off. Also modified the structure of the parse method to make it easier to manage. I was checking strFileName length and nullness in two if blocks, so I moved them together. This should make the parse(...) method easier to understand as well. 26/07/2001, 1.18 Fixed some serious bugs. A new method readAndWrite(InputStream in, OutputStream out) which now does the generic processing in common for readAndWriteFile and readFile. The differences are that now the two extra bytes at the end of a file upload are processed once, instead of after each line. Also if an empty file is encountered, an outputstream is opened, but then deleted if no data written to it. The getCharArray() method has been removed. Replaced by the new String(bytes, encoding) method using ISO8859_1 encoding to ensure that extended characters are supported. All creation of strings is done using this encoding. The addition of static methods setEncoding(String) and getEncoding() to allow the use of MultipartRequest with a specific encoding type. All instances of MultipartRequest will utilise the static charEncoding variable value, that the setEncoding() method can be used to set. Hopefully this will not introduce any latent problems. Started to introduce support for multiple file uploads with the same form field name, but not completed for v1.18. 26/06/2001, 1.17 A few _very_ minor fixes. Plus a cool new feature added. The ability to save files into memory. Thanks to Mark Latham for the idea and some of the code. 11/04/2001, 1.16 Added support for multiple parameter values. Also fixed getCharArray(...) method to support parameters with non-english ascii values (ascii above 127). Thanks to Stefan Schmidt & Michael Elvers for this. (No fix yet for reported problems with Tomcat 3.2 or a single extra byte appended to uploads of certain files). By 1.17 hopefully will have a resolution for the second problem. 14/03/2001, 1.15 A new parameter added, intMaxReadBytes, to allow arbitrary length files. Released under the LGPL (Lesser General Public License). 03/02/2001, 1.14 Fix for IE problem with filename being empty. This is because IE includes a default Content-Type even when no file is uploaded. 16/02/2001, 1.13 If an upload directory is not specified, then all file contents are sent into oblivion, but the rest of the parsing works as normal., 1.12 Fix, was allowing zero length files. Will not even create the output file until there is something to write. getFile(String) now returns null, if a zero length file was specified. 06/11/2000, 1.11 Fix, in case Content-type is not specified., 1.1 Removed dependence on Servlets. Now passes in a generic InputStream instead. "Borrowed" readLine from Tomcat 3.1 ServletInputStream class, so we can remove some of the dependencies on ServletInputStream. Fixed bug where a empty INPUT TYPE="FILE" value, would cause an exception., 1.0 Initial Release.
Author:
Jason Pell

Field Summary
static int ABORT_IF_MAX_BYES_EXCEEDED
          Mode
static int CONTENT_TYPE
           
static int CONTENTS
           
static java.lang.String DEF_ENCODING
           
static int FILENAME
          Define the array indexes for the htFiles Object array.
static int IGNORE_FILES_IF_MAX_BYES_EXCEEDED
           
static int MAX_READ_BYTES
          Prevent a denial of service by defining this, will never read more data.
static int RAW_FILENAME
           
static int READ_LINE_BLOCK
          Defines the number of bytes to read per readLine call.
static int SIZE
           
static int TMP_FILENAME
           
 
Constructor Summary
MultipartRequest(java.io.PrintWriter debug, java.lang.String strContentTypeText, int intContentLength, java.io.InputStream in, int intMaxReadBytes)
          Deprecated. Replaced by MultipartRequest(PrintWriter, String, int, InputStream, int, boolean, String)
MultipartRequest(java.io.PrintWriter debug, java.lang.String strContentTypeText, int intContentLength, java.io.InputStream in, int intMaxReadBytes, int maxBytesExceededMode, java.lang.String encoding)
          Memory Constructor
MultipartRequest(java.io.PrintWriter debug, java.lang.String strContentTypeText, int intContentLength, java.io.InputStream in, int intMaxReadBytes, java.lang.String encoding)
          Memory Constructor
MultipartRequest(java.io.PrintWriter debug, java.lang.String strContentTypeText, int intContentLength, java.io.InputStream in, java.lang.String strSaveDirectory)
          Deprecated. Replaced by MultipartRequest(PrintWriter, String, int, InputStream, String, int, boolean, String)
MultipartRequest(java.io.PrintWriter debug, java.lang.String strContentTypeText, int intContentLength, java.io.InputStream in, java.lang.String strSaveDirectory, int intMaxReadBytes)
          Deprecated. Replaced by MultipartRequest(PrintWriter, String, int, InputStream, String, int, boolean, String)
MultipartRequest(java.io.PrintWriter debug, java.lang.String strContentTypeText, int intContentLength, java.io.InputStream in, java.lang.String strSaveDirectory, int intMaxReadBytes, int maxBytesExceededMode, java.lang.String encoding)
          Standard Constructor
MultipartRequest(java.io.PrintWriter debug, java.lang.String strContentTypeText, int intContentLength, java.io.InputStream in, java.lang.String strSaveDirectory, int intMaxReadBytes, java.lang.String encoding)
          Standard Constructor
MultipartRequest(java.lang.String strContentTypeText, int intContentLength, java.io.InputStream in, java.lang.String strSaveDirectory)
          Deprecated. Replaced by MultipartRequest(PrintWriter, String, int, InputStream, String, int, boolean, String)
MultipartRequest(java.lang.String strContentTypeText, int intContentLength, java.io.InputStream in, java.lang.String strSaveDirectory, int intMaxReadBytes)
          Deprecated. Replaced by MultipartRequest(PrintWriter, String, int, InputStream, String, int, boolean, String)
 
Method Summary
protected  void debug(java.lang.String x)
          Use when debugging this object.
 java.lang.String getBaseFilename(java.lang.String strName)
          Get the uploaded file basename.
 java.lang.String getContentType(java.lang.String strName)
          Returns the Content-Type of a file.
 java.lang.String getEncoding()
          Returns the current encoding method.
 java.io.File getFile(java.lang.String strName)
          Returns a File reference to the uploaded file.
 java.io.InputStream getFileContents(java.lang.String strName)
          If files were uploaded into memory, this method will retrieve the contents of the file as a InputStream.
 java.lang.Object getFileParameter(java.lang.String strName, int type)
          Access an attribute of a file upload parameter record.
 java.util.Enumeration getFileParameterNames()
          This enumeration will return all INPUT TYPE=FILE parameter NAMES as encountered during the upload.
 long getFileSize(java.lang.String strName)
          Returns the File Size of a uploaded file.
 java.lang.String getFileSystemName(java.lang.String strName)
          Deprecated. Replaced by getBaseFilename(String)
 java.lang.String getHtmlTable()
          For debugging.
 java.util.Enumeration getParameterNames()
          An enumeration of all URL Parameters for the current HTTP Request.
 java.lang.String getRawFilename(java.lang.String strName)
          Get the uploaded file basename.
 java.lang.String getURLParameter(java.lang.String strName)
          Return the value of the strName URLParameter.
 java.util.Enumeration getURLParameters(java.lang.String strName)
          Return an enumeration of all values for the strName parameter.
 boolean isMaxBytesExceeded()
          If this class was constructed with a maxBytesExceeded mode of MultipartRequest.IGNORE_FILES_IF_MAX_BYES_EXCEEDED, this method will indicate whether the process is ignoring file content because the content-length was exceeded.
 void setEncoding(java.lang.String enc)
          Sets up the encoding for this instance of multipartrequest.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEF_ENCODING

public static final java.lang.String DEF_ENCODING
See Also:
Constant Field Values

MAX_READ_BYTES

public static final int MAX_READ_BYTES
Prevent a denial of service by defining this, will never read more data. If Content-Length is specified to be more than this, will throw an exception. This limits the maximum number of bytes to the value of an int, which is 2 Gigabytes.

See Also:
Constant Field Values

READ_LINE_BLOCK

public static final int READ_LINE_BLOCK
Defines the number of bytes to read per readLine call. 128K

See Also:
Constant Field Values

FILENAME

public static final int FILENAME
Define the array indexes for the htFiles Object array.

See Also:
Constant Field Values

CONTENT_TYPE

public static final int CONTENT_TYPE
See Also:
Constant Field Values

SIZE

public static final int SIZE
See Also:
Constant Field Values

CONTENTS

public static final int CONTENTS
See Also:
Constant Field Values

TMP_FILENAME

public static final int TMP_FILENAME
See Also:
Constant Field Values

RAW_FILENAME

public static final int RAW_FILENAME
See Also:
Constant Field Values

ABORT_IF_MAX_BYES_EXCEEDED

public static final int ABORT_IF_MAX_BYES_EXCEEDED
Mode

See Also:
Constant Field Values

IGNORE_FILES_IF_MAX_BYES_EXCEEDED

public static final int IGNORE_FILES_IF_MAX_BYES_EXCEEDED
See Also:
Constant Field Values
Constructor Detail

MultipartRequest

public MultipartRequest(java.lang.String strContentTypeText,
                        int intContentLength,
                        java.io.InputStream in,
                        java.lang.String strSaveDirectory)
                 throws java.lang.IllegalArgumentException,
                        java.io.IOException
Deprecated. Replaced by MultipartRequest(PrintWriter, String, int, InputStream, String, int, boolean, String)

Standard Constructor

Parameters:
strContentTypeText - The "Content-Type" HTTP header value.
intContentLength - The "Content-Length" HTTP header value.
in - The InputStream to read and parse.
strSaveDirectory - The temporary directory to save the file from where they can then be moved to wherever by the
Throws:
java.lang.IllegalArgumentException - If the strContentTypeText does not contain a Content-Type of "multipart/form-data" or the boundary is not found.
java.io.IOException - If the intContentLength is higher than MAX_READ_BYTES or strSaveDirectory is invalid or cannot be written to.
See Also:
MAX_READ_BYTES

MultipartRequest

public MultipartRequest(java.lang.String strContentTypeText,
                        int intContentLength,
                        java.io.InputStream in,
                        java.lang.String strSaveDirectory,
                        int intMaxReadBytes)
                 throws java.lang.IllegalArgumentException,
                        java.io.IOException
Deprecated. Replaced by MultipartRequest(PrintWriter, String, int, InputStream, String, int, boolean, String)

Standard Constructor

Parameters:
strContentTypeText - The "Content-Type" HTTP header value.
intContentLength - The "Content-Length" HTTP header value.
in - The InputStream to read and parse.
strSaveDirectory - The temporary directory to save the file from where they can then be moved to wherever by the calling process. If you specify null for this parameter, then any files uploaded will be silently ignored.
intMaxReadBytes - Overrides the MAX_BYTES_READ value, to allow arbitrarily long files.
Throws:
java.lang.IllegalArgumentException - If the strContentTypeText does not contain a Content-Type of "multipart/form-data" or the boundary is not found.
java.io.IOException - If the intContentLength is higher than MAX_READ_BYTES or strSaveDirectory is invalid or cannot be written to.
See Also:
MAX_READ_BYTES

MultipartRequest

public MultipartRequest(java.io.PrintWriter debug,
                        java.lang.String strContentTypeText,
                        int intContentLength,
                        java.io.InputStream in,
                        java.lang.String strSaveDirectory)
                 throws java.lang.IllegalArgumentException,
                        java.io.IOException
Deprecated. Replaced by MultipartRequest(PrintWriter, String, int, InputStream, String, int, boolean, String)

Standard Constructor

Parameters:
debug - A PrintWriter that can be used for debugging.
strContentTypeText - The "Content-Type" HTTP header value.
intContentLength - The "Content-Length" HTTP header value.
in - The InputStream to read and parse.
strSaveDirectory - The temporary directory to save the file from where they can then be moved to wherever by the calling process. If you specify null for this parameter, then any files uploaded will be silently ignored.
Throws:
java.lang.IllegalArgumentException - If the strContentTypeText does not contain a Content-Type of "multipart/form-data" or the boundary is not found.
java.io.IOException - If the intContentLength is higher than MAX_READ_BYTES or strSaveDirectory is invalid or cannot be written to.
See Also:
MAX_READ_BYTES

MultipartRequest

public MultipartRequest(java.io.PrintWriter debug,
                        java.lang.String strContentTypeText,
                        int intContentLength,
                        java.io.InputStream in,
                        int intMaxReadBytes)
                 throws java.lang.IllegalArgumentException,
                        java.io.IOException
Deprecated. Replaced by MultipartRequest(PrintWriter, String, int, InputStream, int, boolean, String)

Memory Constructor

Parameters:
debug - A PrintWriter that can be used for debugging.
strContentTypeText - The "Content-Type" HTTP header value.
intContentLength - The "Content-Length" HTTP header value.
in - The InputStream to read and parse.
intMaxReadBytes - Overrides the MAX_BYTES_READ value, to allow arbitrarily long files.
Throws:
java.lang.IllegalArgumentException - If the strContentTypeText does not contain a Content-Type of "multipart/form-data" or the boundary is not found.
java.io.IOException - If the intContentLength is higher than MAX_READ_BYTES or strSaveDirectory is invalid or cannot be written to.
See Also:
MAX_READ_BYTES

MultipartRequest

public MultipartRequest(java.io.PrintWriter debug,
                        java.lang.String strContentTypeText,
                        int intContentLength,
                        java.io.InputStream in,
                        java.lang.String strSaveDirectory,
                        int intMaxReadBytes)
                 throws java.lang.IllegalArgumentException,
                        java.io.IOException,
                        java.io.UnsupportedEncodingException
Deprecated. Replaced by MultipartRequest(PrintWriter, String, int, InputStream, String, int, boolean, String)

Standard Constructor

Parameters:
debug - A PrintWriter that can be used for debugging.
strContentTypeText - The "Content-Type" HTTP header value.
intContentLength - The "Content-Length" HTTP header value.
in - The InputStream to read and parse.
strSaveDirectory - The temporary directory to save the file from where they can then be moved to wherever by the calling process. If you specify null for this parameter, then any files uploaded will be silently ignored.
Throws:
java.lang.IllegalArgumentException - If the strContentTypeText does not contain a Content-Type of "multipart/form-data" or the boundary is not found.
java.io.IOException - If the intContentLength is higher than MAX_READ_BYTES or strSaveDirectory is invalid or cannot be written to.
java.io.UnsupportedEncodingException
See Also:
MAX_READ_BYTES

MultipartRequest

public MultipartRequest(java.io.PrintWriter debug,
                        java.lang.String strContentTypeText,
                        int intContentLength,
                        java.io.InputStream in,
                        java.lang.String strSaveDirectory,
                        int intMaxReadBytes,
                        java.lang.String encoding)
                 throws java.lang.IllegalArgumentException,
                        java.io.IOException,
                        java.io.UnsupportedEncodingException
Standard Constructor

Parameters:
debug - A PrintWriter that can be used for debugging.
strContentTypeText - The "Content-Type" HTTP header value.
intContentLength - The "Content-Length" HTTP header value.
in - The InputStream to read and parse.
strSaveDirectory - The temporary directory to save the file from where they can then be moved to wherever by the calling process. If you specify null for this parameter, then any files uploaded will be silently ignored.
intMaxReadBytes - Overrides the MAX_BYTES_READ value, to allow arbitrarily long files.
encoding - Sets the encoding to use. If null, ISO-8859-1 will be used.
Throws:
java.lang.IllegalArgumentException - If the strContentTypeText does not contain a Content-Type of "multipart/form-data" or the boundary is not found.
java.io.IOException - If the intContentLength is higher than MAX_READ_BYTES or strSaveDirectory is invalid or cannot be written to.
java.io.UnsupportedEncodingException - If the encoding is invalid.
See Also:
MAX_READ_BYTES

MultipartRequest

public MultipartRequest(java.io.PrintWriter debug,
                        java.lang.String strContentTypeText,
                        int intContentLength,
                        java.io.InputStream in,
                        int intMaxReadBytes,
                        java.lang.String encoding)
                 throws java.lang.IllegalArgumentException,
                        java.io.IOException,
                        java.io.UnsupportedEncodingException
Memory Constructor

Parameters:
debug - A PrintWriter that can be used for debugging.
strContentTypeText - The "Content-Type" HTTP header value.
intContentLength - The "Content-Length" HTTP header value.
in - The InputStream to read and parse.
intMaxReadBytes - Overrides the MAX_BYTES_READ value, to allow arbitrarily long files.
encoding - Sets the encoding to use. If null, ISO-8859-1 will be used.
Throws:
java.lang.IllegalArgumentException - If the strContentTypeText does not contain a Content-Type of "multipart/form-data" or the boundary is not found.
java.io.IOException - If the intContentLength is higher than MAX_READ_BYTES or strSaveDirectory is invalid or cannot be written to.
java.io.UnsupportedEncodingException - If the encoding is invalid.
See Also:
MAX_READ_BYTES

MultipartRequest

public MultipartRequest(java.io.PrintWriter debug,
                        java.lang.String strContentTypeText,
                        int intContentLength,
                        java.io.InputStream in,
                        java.lang.String strSaveDirectory,
                        int intMaxReadBytes,
                        int maxBytesExceededMode,
                        java.lang.String encoding)
                 throws java.lang.IllegalArgumentException,
                        java.io.IOException,
                        java.io.UnsupportedEncodingException
Standard Constructor

Parameters:
debug - A PrintWriter that can be used for debugging.
strContentTypeText - The "Content-Type" HTTP header value.
intContentLength - The "Content-Length" HTTP header value.
in - The InputStream to read and parse.
strSaveDirectory - The temporary directory to save the file from where they can then be moved to wherever by the calling process. If you specify null for this parameter, then any files uploaded will be silently ignored.
intMaxReadBytes - Overrides the MAX_BYTES_READ value, to allow arbitrarily long files.
maxBytesExceededMode - This controls how the parser will process a request which is in excess of the intMaxReadBytes parameter. The possible modes are:

MultipartRequest

public MultipartRequest(java.io.PrintWriter debug,
                        java.lang.String strContentTypeText,
                        int intContentLength,
                        java.io.InputStream in,
                        int intMaxReadBytes,
                        int maxBytesExceededMode,
                        java.lang.String encoding)
                 throws java.lang.IllegalArgumentException,
                        java.io.IOException,
                        java.io.UnsupportedEncodingException
Memory Constructor

Parameters:
debug - A PrintWriter that can be used for debugging.
strContentTypeText - The "Content-Type" HTTP header value.
intContentLength - The "Content-Length" HTTP header value.
in - The InputStream to read and parse.
intMaxReadBytes - Overrides the MAX_BYTES_READ value, to allow arbitrarily long files.
maxBytesExceededMode - This controls how the parser will process a request which is in excess of the intMaxReadBytes parameter. The possible modes are:
Method Detail

setEncoding

public void setEncoding(java.lang.String enc)
                 throws java.io.UnsupportedEncodingException
Sets up the encoding for this instance of multipartrequest. You can set the encoding to null, in which case the default encoding will be applied. The default encoding if this method is not called has been set to ISO-8859-1, which seems to offer the best hope of support for international characters, such as german "Umlaut" characters.

Throws:
java.io.UnsupportedEncodingException

getEncoding

public java.lang.String getEncoding()
Returns the current encoding method.


isMaxBytesExceeded

public boolean isMaxBytesExceeded()
If this class was constructed with a maxBytesExceeded mode of MultipartRequest.IGNORE_FILES_IF_MAX_BYES_EXCEEDED, this method will indicate whether the process is ignoring file content because the content-length was exceeded.


getURLParameter

public java.lang.String getURLParameter(java.lang.String strName)
Return the value of the strName URLParameter. If more than one value for a particular Parameter, will return the first. If an error occurs will return null.


getURLParameters

public java.util.Enumeration getURLParameters(java.lang.String strName)
Return an enumeration of all values for the strName parameter. Even if a single value for, will always return an enumeration, although it may actually be empty if not value was encountered for strName or it is an invalid parameter name.


getParameterNames

public java.util.Enumeration getParameterNames()
An enumeration of all URL Parameters for the current HTTP Request.


getFileParameterNames

public java.util.Enumeration getFileParameterNames()
This enumeration will return all INPUT TYPE=FILE parameter NAMES as encountered during the upload.


getContentType

public java.lang.String getContentType(java.lang.String strName)
Returns the Content-Type of a file.

See Also:
getFileParameter(java.lang.String, int)

getFileContents

public java.io.InputStream getFileContents(java.lang.String strName)
If files were uploaded into memory, this method will retrieve the contents of the file as a InputStream.

Returns:
the contents of the file as a InputStream, or null if not file uploaded, or file uploaded to file system directory.
See Also:
getFileParameter(java.lang.String, int)

getFile

public java.io.File getFile(java.lang.String strName)
Returns a File reference to the uploaded file. This reference is to the files uploaded location, and allows you to read/move/delete the file. This method is only of use, if files were uploaded to the file system. Will return null if uploaded to memory, in which case you should use getFileContents(strName) instead.

Returns:
Returns a null file reference if a call to getFileSize(strName) returns zero or files were uploaded to memory.
See Also:
getFileSize(java.lang.String), getFileContents(java.lang.String)

getFileSystemName

public java.lang.String getFileSystemName(java.lang.String strName)
Deprecated. Replaced by getBaseFilename(String)


getBaseFilename

public java.lang.String getBaseFilename(java.lang.String strName)
Get the uploaded file basename. This is the basename of the file which was provided by the browser itself when the file was chosen using the 'Browse...' button of the <input type=file ...> input field.

Returns:
null if strName not found.
See Also:
getFileParameter(java.lang.String, int)

getRawFilename

public java.lang.String getRawFilename(java.lang.String strName)
Get the uploaded file basename. This is the file which was provided by the browser itself when the file was chosen using the 'Browse...' button of the <input type=file ...> input field.

Returns:
null if strName not found.
See Also:
getFileParameter(java.lang.String, int)

getFileSize

public long getFileSize(java.lang.String strName)
Returns the File Size of a uploaded file.

Returns:
-1 if file size not defined.
See Also:
getFileParameter(java.lang.String, int)

getFileParameter

public java.lang.Object getFileParameter(java.lang.String strName,
                                         int type)
Access an attribute of a file upload parameter record.

Parameters:
strName - is the form field name, used to upload the file. This identifies the formfield location in the storage facility.
type - What attribute you want from the File Parameter.
                        The following types are supported:
                MultipartRequest.FILENAME, 
                MultipartRequest.CONTENT_TYPE, 
                MultipartRequest.SIZE,
                MultipartRequest.CONTENTS,
                MultipartRequest.TMP_FILENAME
                MultipartRequest.RAW_FILENAME
                    

The getBaseFilename(),getFile(),getFileSize(),getContentType(),getContents() methods all use this method passing in a different type argument.

Note: This class has been changed to provide for future functionality where you will be able to access all files uploaded, even if they are uploaded using the same form field name. At this point however, only the first file uploaded via a form field name is accessible.

See Also:
getContentType(java.lang.String), getFileSize(java.lang.String), getFileContents(java.lang.String), getFile(java.lang.String), getBaseFilename(java.lang.String)

debug

protected void debug(java.lang.String x)
Use when debugging this object.


getHtmlTable

public java.lang.String getHtmlTable()
For debugging. Be aware that if you have a form with multiple FILE input types of the same name, only the first one will actually be returned from the getFileParameter(...) method, which all the file access methods call. So if your upload file was actually uploaded against the second file input field, then it will not be accessible, via the methods.