com.ebasetech.xi.api
Class UploadOptions

java.lang.Object
  extended by com.ebasetech.xi.api.UploadOptions
All Implemented Interfaces:
java.io.Serializable

public class UploadOptions
extends java.lang.Object
implements java.io.Serializable

The UploadOptions class supplies a number of options used when a file is uploaded from a browser to a server. It is used as an argument for WebForm.uploadFileFromBrowser(UploadOptions).

The following properties are available. If a property is not specified, the corresponding system default from UFSSetup.properties is used.

The 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.

Further documentation.

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
UploadOptions()
           
 
Method Summary
 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[] 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.
 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 Detail

UploadOptions

public UploadOptions()
Method Detail

getDirectory

public java.lang.String getDirectory()
The directory where uploaded files will be saved. See setDirectory(String).

Returns:
directory
Since:
V4.5

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 property Ufs.pdfDirectoryName in the UFSSetup.properties file. 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);
 

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. See setFileTypes(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 property Ufs.uploadFileTypes in the UFSSetup.properties file. 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);
 

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). See setMaxFileSize(String).

Returns:
maximum file size
Since:
V4.5

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 property Ufs.maxUploadFileSize in the UFSSetup.properties file. 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);     
 

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. See 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.

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