File Download

Description

Download a file from the server to the user's machine.

Used with the Grid and UX components

 File Download in a UX Component

In order to add an event handler that performs a file download action for an embedded object (i.e. a file that is stored in a binary field in a table), you must add a special [File Upload/Download] control to the UX component.

The [File Upload/Download] control is in the Other Controls section of the Toolbox.

Once you have added the [File Upload/Download] control, you can then use Action Javascript to define a File Download action.

 File Download Properties

Type
Specify the type of file download action you want to define.
Filename
Specify the filename to download. The name you specify here is the fully qualified name of a file on your server, NOT a file on this computer! You can also specify a URL.
Fieldname (referenced file)
Specify the name of the control that contains a reference to a file (i.e. a filename, or a URL). The reference can be a relative or absolute filename, or a URL.
Image field
Specify the name of the control that contains the image you want to download. The field can contain an embedded image or a reference to an image filename. If it is a reference, it can be an absolute or relative filename.
Object field
Specify the name of the field in the table the Grid is based on that contains the embedded object. An 'embedded' object is some binary object (e.g. a .pdf file) that is embedded into a field in table that the grid is based on.
Export filename
Specify the name of temporary file that the embedded object will be exported to before it is downloaded. Be sure that the filename specifies the appropriate extension. For example if the embedded object is .pdf data, specify a .pdf filename. If the embedded object type varies from row to row (e.g. row 1 contains a .pdf file, row 2 contains a .xls file), then you can leave the extension out and the appropriate extension will be set at runtime (based on the value in the 'Object type Field' or 'Object type' property)
Object type mode
Specify if the type of the embedded object is the same for each row in the table, or if it can vary from row to row. Choices include Dynamic, Fixed.
Object type
Specify the type of the embedded object (e.g. .pdf, .xls, .jpg, .doc, .docx, etc.)
Object type field
If the embedded object type varies from row to row (e.g. row 1 contains a .pdf file, row 2 contains a .xlsx file, row 3 contains a .docx file, etc.), you can specify the name of a field in the table that stores the object type for the current row. The data stored in the field must be the file type extension. e.g. .pdf, .xlsx, .zip, etc.
Folder name
If the filename that is stored in the control is a relative filename, specify the folder where the physical file is stored. You can specify an absolute, or relative folder name. If you specify a relative folder name, it is relative to the application root (request.ApplicationRoot). You can use the special '<UserSessionFolder>' placeholder in the folder name to indicate the user's session folder. NOTE: In V12 and above, <UserSessionFolder> is not supported.
Javascript
Specify the name of the Javascript function to call. This function should return the name of the file you want to download. The function should be defined in the 'Javascript Declarations' property. For example: myjsfunction()
Xbasic function
Specify the name of the Xbasic function to call. Click the hyperlink below for a sample Xbasic function. The sample will show what properties the Xbasic function is expected to set.
Client-side filename
Specify the default filename to use when saving the file on the user's computer. The user can override the suggested name. If you set the name to <Default>, then (for a linked file), the filename of the file on the server will be used. For an embedded object, a system generated filename will be used. If you specify a client-side filename with no extension, the extension of the file being downloaded will be used. TIP: You can call a Javascript function to dynamically generate the name of the client-side filename. To specify a Javascript function enter: function:nameOfYourJavascriptFunction. For example: function:setFilename, where 'setFilename' is the name of your Javascript function. The value returned by your Javascript function must be url encoded.
File not found action
Specify what action to take if the file to download is not found on the server machine. Choices include.
File not found message
Specify the message to show if the file was not found on the server. You can include the {filename} or {shortFilename} placeholder in the message. {filename} - full filename including drive and path, {shortfilename} - name only. You can use Text Dictionary Tags ( <a5:t> tags) (but NOT <a5:r> tags) in the message to localize the message.
Display permission denied message
If permission to download the file is denied (because of settings in the Project Properties), should a message be displayed?

 Amazon S3 Properties Properties

How to specify Amazon credentials
Specify if the Amazon credentials should be specified now, or should be specified as part of the name of the object you want to download. Click the smart field for more information.
Method for specifying Amazon credentials
Method for specifying Amazon credentials property. Choices include ConnectionString, Explicit.
Connection string
IMPORTANT: The storage connection string MUST NOT BE ENCRYPTED.
Secret
Secret property.
Access key
Access key property.
Bucket
Bucket property.
Method for specifying Amazon object name to download
Method for specifying Amazon object name to download property. Choices include Explicit, Field name, Javascript.
Explicit object name
Explicit object name property.
Javascript function to return object name
Specify the name of the Javascript to call to get the object name. The function must return the name of the object to download.
Field name
Field name property.
Download mode
'Indirect' - file is downloaded from S3 to the Alpha Anywhere server and then sent to the client - download behaves just like any other download option. User will be prompted to save the file. 'Direct' - file is downloaded directly from Amazon S3 to the client - For images, PDFs (and other file types for which the browser has built-in support) will be displayed on the client (the user will NOT get a prompt to save the file). Choices include Indirect, Direct.
ID of image element where images should be shown
The user will not get a prompt to save the image. Instead, the image will be displayed on the client. Specify the id of the <img> element where the image should be displayed.
ID of IFrame where PDFs should be shown
The user will not get a prompt to save the PDF. Instead, the image will be displayed on the client. Specify the id of the <IFrame> element where the PDF should be displayed.

 Javascript events Properties

canFileDownload
Specify the name of the Javascript function to call before the file download begins. The function must return true or false. If the function returns false then the download is aborted. You can use this function to put up a wait message and to lock the user interface.

 Videos

Tutorial - Uploading Files and Images to a Data Bound UX Component

When you upload a file or an image to a data bound UX component, the assumption is that you want to store the uploaded image or file in the record to which the UX component is bound. You can either store the binary data that was uploaded in a field in the record, or you can save the binary data that was uploaded into a file on the server and then store the filename of the file in a character field in the record.

In this video we show how image upload and file upload to a data bound UX component can be done. Images and files are uploaded to both binary and character fields in the record.

Download Component

2014-10-02

The zip file also contains the MySQL SQL script to create the table that the UX component is based on.

See Also