public class FileUpload
extends java.lang.Object
implements java.io.Serializable
IMPORTANT: When a submitted html form is processed by this class, the form fields are read in the order in which they appear on the form. Form field values that are critical to the file upload process must therefore appear on the form before the <input type="file"...> form field that defines the file being uploaded, otherwise the critical values won't be known until after the file has being uploaded.
Modifier and Type | Field and Description |
---|---|
private BaseServletContext |
ivContext
The current context for the servlet or thread using this class.
|
private FileUploadListener |
ivListener
The class that will receive file upload event notifications.
|
private java.util.HashMap<java.lang.String,java.lang.String> |
ivParams
The submitted form fields and their values.
|
private static long |
serialVersionUID
The class' serialization version id.
|
private static java.io.File |
TEMP_FOLDER
The site's configured temporary file folder.
|
Constructor and Description |
---|
FileUpload(FileUploadListener listener,
BaseServletContext ctx)
Constructs a new instance of the file upload class with the given servlet
or thread context.
|
Modifier and Type | Method and Description |
---|---|
void |
deleteFromTemp(java.lang.String fileName)
Deletes an uploaded file from the site's configured temporary folder.
|
BaseServletContext |
getContext()
Returns the current context for the servlet or thread using this class.
|
boolean |
isFileUpload()
Answers if a file upload is to be processed based on whether a submitted
servlet request's content type is "multipart/form-data".
|
boolean |
moveFromTemp(java.lang.String fileName,
java.lang.String destPath)
Moves an uploaded file from the site's configured temporary folder to the
given destination folder.
|
boolean |
moveFromTemp(java.lang.String fileName,
java.lang.String destPath,
java.lang.String destName)
Moves an uploaded file from the site's configured temporary folder to the
given destination folder.
|
private void |
sendEvent(java.lang.String field,
java.lang.String file,
int error)
Sends a file upload event to the upload listener.
|
boolean |
uploadToTemp(long maxSize)
Uploads the requested file(s) to the site's configured temporary folder
by parsing and processing submitted multipart/form-data.
|
private static final long serialVersionUID
private static final java.io.File TEMP_FOLDER
private FileUploadListener ivListener
private BaseServletContext ivContext
private java.util.HashMap<java.lang.String,java.lang.String> ivParams
public FileUpload(FileUploadListener listener, BaseServletContext ctx)
listener
- (FileUploadListener) The class that will receive
file upload event notifications.ctx
- (BaseServletContext) The current servlet or thread context.public BaseServletContext getContext()
public boolean isFileUpload()
true
if a file upload is to be processed,
otherwise false
.public boolean uploadToTemp(long maxSize)
IMPORTANT: When a submitted html form is processed by this method, the form fields are read in the order in which they appear on the form. Form field values that are critical to the file upload process must therefore appear on the form before the <input type="file"...> form field that defines the file being uploaded, otherwise the critical values won't be known until after the file has being uploaded.
maxSize
- (long) The maximum upload file size allowed. A value
of zero indicates that there is no maximum.true
if the upload completes successfully,
otherwise false
.public void deleteFromTemp(java.lang.String fileName)
fileName
- (String) The name of the uploaded file.public boolean moveFromTemp(java.lang.String fileName, java.lang.String destPath)
fileName
- (String) The name of the uploaded file.destPath
- (String) The fully qualified path to where the file
is to be moved.true
if moving the file is successful,
otherwise false
.public boolean moveFromTemp(java.lang.String fileName, java.lang.String destPath, java.lang.String destName)
fileName
- (String) The name of the uploaded file.destPath
- (String) The fully qualified path to where the file
is to be moved.destName
- (String) The name of the destination file.true
if moving the file is successful,
otherwise false
.private void sendEvent(java.lang.String field, java.lang.String file, int error)
field
- (String) The name of the form field being processed.file
- (String) The name of the file being processed.error
- (int) The upload processing's error code.