Class UploadOptions
- All Implemented Interfaces:
java.io.Serializable
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 propertyUfs.fileDirectoryName
)maxFileSize
- the maximum file size that can be uploaded (default propertyUfs.maxUploadFileSize
)fileTypes
- the file types that can be uploaded (default propertyUfs.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
- Since:
- V4.5
- See Also:
- Serialized Form
-
Constructor Summary
Constructors Constructor Description UploadOptions()
-
Method Summary
Modifier and Type Method 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.Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Constructor Details
-
UploadOptions
public UploadOptions()
-
-
Method Details
-
getDirectory
public java.lang.String getDirectory()The directory where uploaded files will be saved. SeesetDirectory(String)
.- Returns:
- directory
- Since:
- V4.5
-
getDirectoryInternal
public java.lang.String getDirectoryInternal() -
setDirectory
public 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. The default directory is specified in server propertyUfs.pdfDirectoryName
(configured using the server administration application). If set tonull
, 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);
- Parameters:
directory
-- Since:
- V4.5
-
getFileTypes
public java.lang.String[] getFileTypes()An array of allowable case insensitive file types that can be uploaded. If the user attempts to upload a file with a type not in this list, an error message is issued. SeesetFileTypes(String[])
.See also
mimeTypes
which specifies the default file types for user browsing.- Returns:
- fileTypes
- Since:
- V4.5
-
setFileTypes
public void setFileTypes(java.lang.String[] fileTypes)Sets the list of case insensitive file types that can be uploaded. If the user attempts to upload a file with a type not in this list, an error message is issued. The default allowable file types are specified in server propertyUfs.uploadFileTypes
(configured using the server administration application). If set tonull
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);
- Parameters:
fileTypes
- an array of allowable file types- Since:
- V4.5
-
getMaxFileSize
public java.lang.String getMaxFileSize()The maximum size of file that can be uploaded. If the user attempts to upload a file larger than this, an error message is issued. Can be specified as an integer, or an integer terminated by K(kilobytes) or M(Megabytes). SeesetMaxFileSize(String)
.- Returns:
- maximum file size
- Since:
- V4.5
-
getMaxFileSizeInternal
public java.lang.String getMaxFileSizeInternal() -
setMaxFileSize
public void setMaxFileSize(java.lang.String maxFileSize)Sets the maximum size for an uploadable file. If the user attempts to upload a file larger than this, an error message is issued. Can be specified as an integer, or an integer terminated by K(kilobytes) or M(Megabytes). The default value is specified in server propertyUfs.maxUploadFileSize
(configured using the server administration application). If set tonull
, 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);
- Parameters:
maxFileSize
- maximum file size nnnn, nnnK or nnnM- Since:
- V4.5
-
getAcceptedMimeTypes
public java.lang.String[] getAcceptedMimeTypes()An array of accepted MIME types. These are used to constrain the file types that the user can select while browsing and are implemented using the "accept" parameter of the HTML input tag. Browsers vary in the way this parameter is supported - some allow the user to upload additional file types and some don't, and some browsers do not support it at all - notably Internet Explorer prior to version 10. SeesetAcceptedMimeTypes(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.- Returns:
- accepted MIME types
- Since:
- V4.5
-
setAcceptedMimeTypes
public void setAcceptedMimeTypes(java.lang.String[] acceptedMimeTypes)Sets the list of accepted MIME types. These are used to constrain the file types that the user can select while browsing and are implemented using the "accept" parameter of the HTML input tag. Browsers vary in the way this parameter is supported - some allow the user to upload additional file types and some don't, and some browsers do not support it at all - notably Internet Explorer prior to version 10.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);
- Parameters:
acceptedMimeTypes
- an array of allowable MIME types- Since:
- V4.5
-