public class UploadOptions
extends java.lang.Object
implements java.io.Serializable
WebForm.uploadFileFromBrowser(UploadOptions)
.
The following properties are available. If a property is not specified, the corresponding system default from server properties (configured using the server administration application) is used.
directory
- the target directory on the server (default property Ufs.fileDirectoryName
)maxFileSize
- the maximum file size that can be uploaded (default property Ufs.maxUploadFileSize
)fileTypes
- the file types that can be uploaded (default property Ufs.uploadFileTypes
)acceptedMimeTypes
- the accepted MIME types - used by supporting browsers to constrain the file types shown in the browse panel (no default)fileTypes
property is a list of file types supported by the server e.g. doc, pdf, txt etc. An error message is issued if the user attempts
to upload a file with a different type.
The acceptedMimeTypes
property is a list of supported MIME types and provides a way of helping the user by setting the file types
in the browse panel. This is implemented using the HTML accept
parameter of the input
tag and the implementation of this parameter varies according
to the browser, with some browsers - notably IE before version 10 - providing no support.
So using MIME types can provide a way of helping some users, but it doesn't provide a way to constrain which files can be uploaded -
use the fileTypes
property to achieve this.
Javascript examples:
var opts1 = new UploadOptions(); opts1.directory = "c:/temp"; // Backslashes should be escaped e.g. c:\\temp form.uploadFileFromBrowser(opts1); // Invoke the upload var opts2 = new UploadOptions(); opts2.acceptedMimeTypes = [ "image/*" ]; // Limit the file types shown in the browser panel opts2.fileTypes = [ "png", "gif", "jpg" ]; // Only these file types can be uploaded form.uploadFileFromBrowser(opts2); // Invoke the upload
Constructor and Description |
---|
UploadOptions() |
Modifier and Type | Method and Description |
---|---|
java.lang.String[] |
getAcceptedMimeTypes()
An array of accepted MIME types.
|
java.lang.String |
getDirectory()
The directory where uploaded files will be saved.
|
java.lang.String |
getDirectoryInternal() |
java.lang.String[] |
getFileTypes()
An array of allowable case insensitive file types that can be uploaded.
|
java.lang.String |
getMaxFileSize()
The maximum size of file that can be uploaded.
|
java.lang.String |
getMaxFileSizeInternal() |
void |
setAcceptedMimeTypes(java.lang.String[] acceptedMimeTypes)
Sets the list of accepted MIME types.
|
void |
setDirectory(java.lang.String directory)
Sets the target directory on the server for uploaded files, and can be either a relative or absolute path.
|
void |
setFileTypes(java.lang.String[] fileTypes)
Sets the list of case insensitive file types that can be uploaded.
|
void |
setMaxFileSize(java.lang.String maxFileSize)
Sets the maximum size for an uploadable file.
|
public java.lang.String getDirectory()
setDirectory(String)
.public java.lang.String getDirectoryInternal()
public void setDirectory(java.lang.String directory)
Ufs.pdfDirectoryName
(configured using the server administration application).
If set to null
, the default value will be used.
In general, it is easier to always use a forward slash (/) as a path separator. If a backslash is used it must be escaped - see second example below.
Javascript examples:
var opts1 = new UploadOptions(); opts1.directory = "C:/temp"; form.uploadFileFromBrowser(opts1); var opts2 = new UploadOptions(); opts2.directory = "C:\\temp"; form.uploadFileFromBrowser(opts2);
directory
- public java.lang.String[] getFileTypes()
setFileTypes(String[])
.
See also mimeTypes
which specifies the default file types for user browsing.
public void setFileTypes(java.lang.String[] fileTypes)
Ufs.uploadFileTypes
(configured using the server administration application).
If set to null
or an empty array, all file types can be uploaded.
See also setAcceptedMimeTypes(String[])
which can be used to set the default file types for user browsing.
Javascript example:
var opts = new UploadOptions(); opts.fileTypes = [ "doc", "pdf", "txt", "zip" ]; form.uploadFileFromBrowser(opts);
fileTypes
- an array of allowable file typespublic java.lang.String getMaxFileSize()
setMaxFileSize(String)
.public java.lang.String getMaxFileSizeInternal()
public void setMaxFileSize(java.lang.String maxFileSize)
Ufs.maxUploadFileSize
(configured using the server administration application).
If set to null
, the default value will be used.
An explicit maximum size value must always be specified, it is not possible to allow upload of files of unlimited size.
Javascript example:
var opts1 = new UploadOptions(); opts1.maxFileSize = "2M"; form.uploadFileFromBrowser(opts1); var opts2 = new UploadOptions(); opts2.maxFileSize = "100000"; form.uploadFileFromBrowser(opts2);
maxFileSize
- maximum file size nnnn, nnnK or nnnMpublic java.lang.String[] getAcceptedMimeTypes()
setAcceptedMimeTypes(String[])
.
Examples of MIME types are image/*, audio/*, video/*. See IANA MIME types for a complete list of standard MIME types.
MIME types should be used to assist the user with browsing their file system; they should not be used as a means of validating which file types
can be uploaded - use fileTypes
to do this.
public void setAcceptedMimeTypes(java.lang.String[] acceptedMimeTypes)
Examples of MIME types are image/*, audio/*, video/*. See IANA MIME types for a complete list of standard MIME types.
MIME types should be used to assist the user with browsing their file system; they should not be used as a means of validating which file types
can be uploaded - use setFileTypes(String[])
to do this.
Javascript example:
var opts = new UploadOptions(); opts.acceptedMimeTypes = [ "image/*", "application/pdf" ]; form.uploadFileFromBrowser(opts);
acceptedMimeTypes
- an array of allowable MIME types