Applet Helper Methods

Following is a list of helper methods, with descriptions of what they do and how to use them.

ueAppletHelper( params, debug )

Constructs an ueAppletHelper object.

ParameterTypeDescription
paramsObjectInitialisation Parameters
debugBooleanDebug flag

The ueAppletHelper object makes it easy to add Upload ease to your web page, handling any changes between versions and differences in applet deployment across browsers. It is the simplest way to ensure maximum compatibility going forward, and minimises the integration effort in using the Software on your web site.

Inside your script element you can instantiate the ueAppletHelper thus...

<body>
  ...
  <script type="text/javascript">
    ...
    
    var ue = new ueAppletHelper( { options... }, true );
    
    ...
  </script>
  ...
</body>
... where options is a comma separated list of configuration parameters. All configuration parameters can be provided here for convenience, but can also be set with the other helper methods as described below.

To aid in debugging your implementation a flag is provided to turn on debugging output. If true, debugging information is written into a separate window, including warnings if unknown option variables are set, and the applet HTML embedded into your web page (when the write method is called).

addImage( image )

Adds an image specifier from an ImageHelper object or a specifier string.

ParameterTypeDescription
imageImageHelper Object or StringImage Specifier

The addImage method can be used to conveniently add an image specifier to the current list of image specifiers for the uploader applet, either from an ImageHelper object or a string in image specifier format.

  ...
  <script type="text/javascript">
    ...
    var ue = new ueAppletHelper( { options... } );
    var ih = new ue.ImageHelper( { width: 100, height: 100 } ); //<= create ImageHelper 
    
    ue.addImage(ih); //<= add image from ImageHelper 
    ue.addImage('400x300:pad=#fff'); //<= add image from specifier string 
    
    ...
  </script>
  ...

addImageDefaults( image_defaults )

Adds an image defaults specifier from an ImageHelper object or a specifier string.

ParameterTypeDescription
image_defaultsImageHelper Object or StringImage Specifier

The addImageDefaults method can be used to conveniently set defaults for subsequent images added to the upload list, either from an ImageHelper object or a string in image specifier format. This is useful when you have a number of images that use the same non-default value for a given image option, and you don't want to have to specify it for each image.

  ...
  <script type="text/javascript">
    ...
    var ue = new ueAppletHelper( { options... } );
    ...
    var ih = new ue.ImageHelper( { pad: '#000' } ); //<= create ImageHelper specifying black padding
    ...
    
    ue.addImageDefaults(ih); //<= images added after this will be padded in black
    
    ...
  </script>
  ...

addToken( tokens )

Appends one or more licence tokens to the current list of tokens.

ParameterTypeDescription
tokensString or ArrayLicence token(s)

The addToken method appends one or more tokens to the list of tokens used by the applet to validate the licence for uploading to the specified domain or server.

Multiple tokens can be specified by passing a string separating them with a semi-colon (;), an array of strings, or by making multiple calls.

  ...
  <script type="text/javascript">
    ...
    var ue = new ueAppletHelper( { options... } );
    ...
    
    ue.addToken('licence_token');
    
    ...
  </script>
  ...

appendParam( name, value )

Appends a value to an AppletHelper option.

ParameterTypeDescription
nameStringParameter Name
valueSee Parameter DetailParameter Value

The appendParam method allows you to append values to certain AppletHelper options.

Usage example:

...
<script type="text/javascript">
  ...
  var ue = new ueAppletHelper( { options... } );
  ...
  
  ue.appendParam('include', 'gif'); //<= appends 'gif' to the file include filter
  
  ...
</script>
...

ImageHelper( options )

Creates a new ImageHelper object for specifying extra images to be uploaded.

ParameterTypeDescription
optionsObjectImage Options

An ImageHelper object can be used to conveniently create and configure an image specifier, used to tell the Upload ease applet to create and upload thumbnails or other images derived from images selected for uploading.

Once configured, simply call the ueAppletHelper method addImage() to append it to the list of extra images to be generated for uploading.

  ...
  <script type="text/javascript">
    ...
    var ue = new ueAppletHelper( { applet options... } );
    ...
    
    var ih = new ue.ImageHelper( { image options... } ); //<= create ImageHelper 
    
    ...
    ue.addImage(ih); //<= add the image to the applet
    ...
  </script>
  ...

setCallbacks( specifiers )

Convenience method for setting various Javascript callback functions.

ParameterTypeDescription
specifiersObjectCallback specifiers

Upload ease uses "callbacks" to provide a convenient way to get input or provide feeback to the user. Currently supported callbacks are as follows:

  • fileParams - called to get or set per file parameters
  • onAbort - called when user aborts/cancels an upload. The bundleGroupId of the aborted upload is passed for reference.
  • onFileUploaded - called when an individual file has been fully uploaded to the server. The progress bar is animated and if this callback returns a string, it is displayed next to the progress bar, until the next file upload begins or all files have finished uploading. The filename of the uploaded file is passed to this callback for convenience.
  • onUploadDone - called when upload completes. The bundleGroupId of the completed upload is passed for reference.
  • uploadParams - called to get extra upload parameters
setCallbacks() may be called multiple times and with multiple callbacks specified each time (with the last specified overriding any earlier specifications).

  ...
  <script type="text/javascript">
    
    var storedFileParams = [];//<= store per file variables

    function fileParamsCallback( action, key ) {
      if (action == 'get') {
        return storedFileParams[key];//<= return URL parameter formatted string
      } else if (action == 'set') {
        ... //<= Initiate user input (e.g. display a form) 
      }
    }

    function onAbort( bundleGroupID ) {
      alert('Upload aborted!');//<= Notify user of upload abort 
    }

    function onFileUploaded( filename ) {
      return 'Processing '+filename+'...';
    }

    function onUploadDone( bundleGroupID ) {
      alert('Upload done!');//<= Notify user of upload completion
    }

    function getUploadParams() {
      return $('#form').serialize();//<= return form variables (e.g. serialized with jQuery)
    }

    
    ...
    var ue = new ueAppletHelper( { options... } );
    ...
    
    ue.setCallbacks({ //<= set one or more callbacks
      fileParams: 'fileParamsCallback',
      onAbort: 'onAbort',
      onFileUploaded: 'onFileUploaded',
      onUploadDone: 'onUploadDone',
      uploadParams: 'getUploadParams'
    });
    
    ...
  </script>
  ...

setCompression( method, include, exclude )

Convenience method for setting the compression method and include/exclude filter when compressing.

ParameterTypeDescription
methodStringCompression Method
includeStringInclude Filename Filter
excludeStringExclude Filename Filter

The setCompression method provides a convenient way to set the upload compression method and include/exclude filters (see the include and exclude helper options documentation for details on specifying include/exclude filters). The example tells the uploader to use Zip compression on files with "txt" or "doc" extensions, but not if their names begin with "compact".

  ...
  <script type="text/javascript">
    ...
    var ue = new ueAppletHelper( { options... } );
    ...
    
    ue.setCompression('zip', ['txt','doc'], '/^compact.*/'); //<= use ZIP compression
    
    ...
  </script>
  ...

setCookies( specifiers )

Convenience method for setting cookies to be passed to the server upload script.

ParameterTypeDescription
specifiersObjectCookie specifiers

Upload ease can send "cookies" with the upload to the server-side processing script. Such cookies are often used in security/authorisation mechanisms to identify the user and enforce upload limits and so on. setCookies() may be called multiple times and with multiple cookies specified each time (with the last specified overriding any earlier specifications).

Usage:

  ...
  <script type="text/javascript">
    var ue = new ueAppletHelper( { options... } );
    ...
    
    ue.setCookies({ //<= set one or more cookies
      name1: 'value1',
      name2: 'value2',
      ...,
      nameN: 'valueN'
    });
    
    ...
  </script>
  ...

setFileFilter( include, exclude )

Convenience method for setting the include/exclude filters.

ParameterTypeDescription
includeStringInclude Filename Filter
excludeStringExclude Filename Filter

This method is a convenience method for setting the filename include/exclude filters that control what files are shown and selectable in the file view pane (see the include and exclude helper options documentation for details on specifying include/exclude filters). The example tells the uploader show files with the image extensions "jpg" or "jpeg" extensions, but not if their names begin with "private".

  ...
  <script type="text/javascript">
    ...
    var ue = new ueAppletHelper( { options... } );
    ...
    
    ue.setFileFilter(['jpg','jpeg'], '/^private.*/'); //<= set filename filter
    
    ...
  </script>
  ...

setHashing( algorithm, hashParameterName, include, exclude )

Convenience method for setting the hashing algorithm, "hashParameterName" configuration parameter and include/exclude filter when hashing.

ParameterTypeDescription
algorithmStringHashing Algorithm
hashParameterNameStringUpload Variable Parameter Name
includeStringInclude Filename Filter
excludeStringExclude Filename Filter

The setHashing method provides a convenient way to set the upload hashing algorithm, hashParameterName, and include/exclude filters (see the include and exclude helper options documentation for details on specifying include/exclude filters). The example tells the uploader to use the SHA hashing algorithm on all files.

Hashing is useful when you need to be sure that files have not been changed or corrupted during upload, by comparing the pre-upload hash with a hash generated on the file once uploaded (using the same hashing algorithm).

Currently supported hashing algorithms are:

  • none (no hashing)
  • md2 (MD2 hashing)
  • md5 (MD5 hashing)
  • sha (SHA hashing)

  ...
  <script type="text/javascript">
    ...
    var ue = new ueAppletHelper( { options... } );
    ...
    
    ue.setHashing('SHA'); //<= use SHA hashing algorithm
    
    ...
  </script>
  ...

setLastFolderVisitedCookie( expiry, path, domain, name )

Convenience method for setting the "LastFolderVisitedCookie" parameters.

ParameterTypeDescription
expiryString | Date | NumberExpiration time
pathStringCookie Path
domainStringCookie domain
nameStringCookie name

The setLastFolderVisitedCookie method provides a convenient way to set the "LastFolderVisitedCookie", which remembers the folder from which files were last uploaded.

As users typically store the files and images they upload in the same folder or folder hierarchy, returning them there next time they wish to upload files can save them a lot of time by not having to navigate from the system root folder.

The cookie's expiry date may be set in several ways, either by a number of seconds relative to the current time, or an absolute date specified by either a date-time string (in a format recognized by the Javascript Date.parse method) or a Javascript Date object.

The cookie path may be set to make it apply across the site ("/") or to specific parts of the site, depending on the application. If your site accepts uploads for different types of files/images that are likely to come from different sources you may want to make use of this parameter. By default the LastFolderVisitedCookie will only apply to the URL of the page that it was embedded in.

In a similar way the domain parameter may be used to set the cookie's domain.

If you wish to use a different name for the LastFolderVisitedCookie you can change it via the name parameter.

  ...
  <script type="text/javascript">
    ...
    var ue = new ueAppletHelper( { options... } );
    ...
    
    var expiry = 3600; //<= expire in 1 hour 
    expiry = 'Jan 1, 2010'; //<= expire on New Year's Day 2010 
    expiry = new Date(2010, 0, 1, 14, 30, 0, 0); //<= expire on New Year's Day 2010 at 2:30pm 

    var path = "/"; //<= apply cookie across the whole site 

    var domain = window.location.host; //<= apply cookie to current domain 

    var name = "lfvc"; //<= use a short name 

    ue.setLastFolderVisitedCookie(expiry, path, domain, name); //<= set "LastFolderVisitedCookie"
    
    ...
  </script>
  ...

setParam( name, value )

Sets an AppletHelper option.

ParameterTypeDescription
nameStringParameter Name
valueSee Parameter DetailParameter Value

The setParam method allows you to specify AppletHelper options individually.

Usage example:

...
<script type="text/javascript">
  ...
  var ue = new ueAppletHelper( { options... } );
  ...
  
  ue.setParam('maxFileCount', 10); //<= sets 'maxFileCount' option to 10
  
  ...
</script>
...

setProperties( specifiers )

Convenience method for setting GUI properties and text translations.

ParameterTypeDescription
specifiersObjectProperty specifiers

Upload ease uses "properties" to provide a convenient way to customise the GUI. We have separated the properties into two groups below, the first is for controlling visual and behavioural aspects of the GUI, and the second is for language translations.

Properties that control visual (e.g. colour) and behavioural (e.g. display of preview images) follow. Colours may be specified by name or hex code as described here. Font names are specified as FontFamilyName-Style-Size (e.g. Courier-plain-10) where style is one of plain, bold, bolditalic, italic. Logical values may be given as true or false, "on" or "off", "yes" or "no", 0 or non-zero. The expected type (Colour, Font, Logical, or URL) is given in parentheses after the property name.

  • backgroundColor (Colour)
  • cancel.button.disabled (Logical)
  • cell.tree.backgroundColor (Colour)
  • cell.tree.backgroundColor.selected (Colour)
  • cell.tree.foregroundColor (Colour)
  • cell.tree.foregroundColor.selected (Colour)
  • errors.view.backgroundColor (Colour)
  • errors.view.clear.button.foregroundColor (Colour)
  • errors.view.font (Font)
  • errors.view.foregroundColor (Colour)
  • fileItem.view.backgroundColor (Colour)
  • folder.view.backgroundColor (Colour)
  • folder.view.font (Font)
  • folder.view.logoIconURL (URL)
  • folder.view.selectAll.button.foregroundColor (Colour)
  • folder.view.unselectAll.button.foregroundColor (Colour)
  • font (Font)
  • foregroundColor (Colour)
  • images.noPreview (Logical)
  • label.fileItem.view.backgroundColor (Colour)
  • label.fileItem.view.font (Font)
  • label.fileItem.view.foregroundColor (Colour)
  • progressBar.backgroundColor (Colour)
  • progressBar.foregroundColor (Colour)
  • selection.view.backgroundColor (Colour)
  • selection.view.font (Font)
  • selection.view.logoIconURL (URL)
  • selection.view.selectAll.button.foregroundColor (Colour)
  • selection.view.unselectAll.button.foregroundColor (Colour)
  • tabs.backgroundColor (Colour)
  • tabs.font (Font)
  • tabs.foregroundColor (Colour)
  • tree.backgroundColor (Colour)
  • tree.font (Font)
  • tree.foregroundColor (Colour)
  • uploadFilename.backgroundColor (Colour)
  • uploadFilename.foregroundColor (Colour)

Properties that specify text can be used to implement language translations, which should be given by UTF-8 encoded strings. For reference, the default (english) text follows each property name in parentheses. Numbers in braces (e.g. {0}, {1}, {2}) are placeholders for variable values (e.g. file names) that are substituted at run-time.

  • addFileNotes.tooltip.text ("Add file notes...")
  • adding.message.text ("Adding {0}")
  • calculatingUploadSize.message.text ("Calculating total upload size...")
  • cancel.button.text ("Cancel")
  • chooseFiles.tabs.text ("Choose Files")
  • clear.errors.button.text ("Clear")
  • droppedItemNotAllowed.message.text ("Dropped item not allowed: '{0}'.")
  • droppedItemNotSupported.message.text ("Dropped item not supported: '{0}'.")
  • editFileNotes.tooltip.text ("Edit file notes...")
  • errors.tabs.text ("Errors")
  • errors.view.clear.button.text ("Clear")
  • exceedUploadFileLimit.message.text ("Uploaded {0} of {1} selected files.")
  • failedToUploadFile.message.text ("Failed to upload file '{0}'.")
  • fileExceedsSizeLimit.message.text ("File '{0}' exceeds size limit ({1} > {2}).")
  • folder.view.selectAll.button.text ("Select All")
  • folder.view.unselectAll.button.text ("Unselect All")
  • maxUploadSizeExceeded.message.text ("Upload size exceeds maxUploadSize limit ({0} > {1}).")
  • noItemsSelected.message.text ("No items selected!")
  • rotateAnticlockwise.tooltip.text ("Rotate anticlockwise")
  • rotateClockwise.tooltip.text ("Rotate clockwise")
  • selectedFiles.tabs.text ("Selected Files")
  • selection.view.selectAll.button.text ("Select All")
  • selection.view.unselectAll.button.text ("Unselect All")
  • selectItems.message.text ("Please select some items to upload.")
  • upload.button.text ("Upload")
  • uploading.message.text ("Uploading {0}")
  • uploadSizeOk.message.text ("Upload size OK!")

Note that property names are formed in a special way that allows related properties to inherit their values (unless overridden). Take the font property for example - if it were set then all properties with font as the right-most component of their name would inherit its value. To then change the font used for a file item's label the label.fileItem.view.font property could be specified to override the parent value. This mechanism makes it easy to customise the general look and feel of the GUI without having to specify each and every property.

setProperties() may be called multiple times and with multiple properties specified each time (with the last specified overriding any earlier specifications).

See the code below for usage examples:

  ...
  <script type="text/javascript">
    ...
    var ue = new ueAppletHelper( { options... } );
    ...
    
    ue.setProperties({ //<= set one or more UI customisation properties
      font: 'Tahoma-plain-10', //<= set font to Tahoma 10pt 
      backgroundColor: '#000', //<= set background colour to black
      foregroundColor: 'white', //<= set foreground colour to white
      logoIconURL: 'http://MySite.com/images/logo.png', //<= set logo (64x32 pixels)
      images.noPreview: true //<= turn image preview generation off
    });
    
    ...
    
    ue.setProperties({ //<= set one or more translation properties
      'view.selectAll.button.text': '选择所有项目', //<= set "Select All" button text for simplified Chinese 
      'view.unselectAll.button.text': '取消所有项目' //<= set "Unselect All" button text for simplified Chinese 
    });
    
    ...
  </script>
  ...

setSession( name, id )

Convenience method for setting name and ID when uploading.

ParameterTypeDescription
nameStringSession Name
idStringSession ID

The setSession method provides a convenient way to set the sessionName and sessionID options of the uploader (see the sessionName and sessionID helper options documentation for details on specifying session cookies). The example shows how to set these values in pages generated by PHP scripts.

  ...
  <script type="text/javascript">
    ...
    var ue = new ueAppletHelper( { options... } );
    ...
    
    ue.setSession('<?=session_name()?>', '<?=session_id()?>'); //<= set session info in PHP 
    
    ...
  </script>
  ...

setVariables( specifiers )

Convenience method for setting upload variables and their names.

ParameterTypeDescription
specifiersObjectVariable specifiers

Upload ease uses "variables" to provide a convenient way to customise the variables sent to the upload processing script. Each variable may be set to true, false, or a string value. If true the variable is uploaded with the same name, if false it is not uploaded, and if set to a string value it is uploaded using that value as the name of the variable. Where applicable the fileIndexPlaceholder parameter is used to substitute file indices into the variable name.

Currently supported variables are as follows:

bundleGroupId
A unique identifier for the current group of upload requests. This is useful when an upload is broken up into multiple bundles (each relating to a single HTTP request) and you need to be able to relate them to each other on the server. It takes the form of a 40 hex-digit string (e.g. B13912A1191B8F1CF98851C77B93F43BB107A125).
bundleCount
The number of bundles in the bundle group (1 if all files are uploaded in a single HTTP request).
bundleIndex
The 0-based index of this bundle in the upload sequence.
bundleSize
The number of files contained in this bundle.
bundleStart
The index of the first file in this bundle with respect to all files in the bundle group (index base given by the fileIndexBase parameter). This variable is not affected by the restartFileIndices parameter.
totalFileCount
The total number of files to be uploaded in this bundle group.
fileCount
The total number of files uploaded in this bundle (same as the bundleSize variable).
fileHashes*
The name of the upload variable containing generated file hashes.
fileNames*
The name of the upload variable containing original file names.
fileParams*
The base name of the upload variable containing per file parameters.
fileParts*
The name of the upload variable containing the uploaded file.
filePaths*
The name of the upload variable containing original file paths (relative to uploaded folders).
setVariables() may be called multiple times and with multiple variables specified each time (with the last specified overriding any earlier specifications).

Upload ease creates the file* upload variable names dynamically for each file where necessary (all except fileCount). Use the fileIndexPlaceholder (defaults to #) in the variable name to have the file index substituted into the variable name.

Note that for per file form variables, the form variable names are appended to the fileParams variable name.

  ...
  <script type="text/javascript">
    ...
    var ue = new ueAppletHelper( { options... } );
    ...
    
    ue.setVariables({ //<= set one or more upload variables
      fileCount: true, //<= turn "fileCount" variable on
      fileParams: 'params_#', //<= per file parameters will be params_1, params_2, ...
      fileParts: 'part_#' //<= file parts will be named file_1, file_2, ...
    });
    
    ...
  </script>
  ...

write( )

Writes an HTML applet element into the page with current option settings.

Once you have configured the ueAppletHelper the way you want it, it is ready to embed in your web page. Calling the write method writes the appropriate HTML applet element into your web page's HTML at the point where it's called.

  ...
  <script type="text/javascript">
    ...
    var ue = new ueAppletHelper( { options... } );
    ...
    
    ue.write(); //<= writes an HTML applet element into your web page 
    
    ...
  </script>
  ...