pui.downloadURL(config)



This API calculates the URL needed to start a download.   This is like pui.download(config), except that it only returns the URL needed to start the download, whereas pui.download() executes the download automatically.   This API is useful when you want to use the PUI download facility to download an image that will be shown in-line on the screen.

In order to use this API, you must first set up the security for it by creating a PUI Download Exit (PUIDNLEXIT) program.  Click Here to Learn How to Create a PUIDNLEXIT Exit Program

Parameters:

  • config object - JavaScript object containing configuration properties

Configuration Options

  • id - file identifier. By default, this is the IFS path to the file you want to download. However, it's also possible to pass some sort of a "key" value here that the PUIDNLEXIT exit program will look for. The exit program could then change it to an IFS path name on-the-fly. This is useful when you want to hide your IFS path names from the browser, or when you want the exit program to create a temporary file on-the-fly to be served to the browser.

  • contentType (optional) - This is the MIME content-type. When opening a document in-line, some browsers use this string to determine if it's capable of viewing the document in it's window, or whether an external viewer is needed. If this parameter is not given, the contentType will be assumed to be "application/octet-stream".

Examples:

This example retrieves the URL needed to download a jpeg image:

var imgurl = pui.downloadURL({ "id": "/images/products/54321.jpg", "contentType": "image/jpeg" }); // the 'imgurl' variable now contains the URL

If you wanted to call the API directly from an image widget, for example, you could set the 'image source' property to:

script: pui.downloadURL({ "id": "/images/products/54321.jpg", "contentType": "image/jpeg" });

The "script:" keyword identifies the property as Javascript code to be run. The API will then be called as the screen is loaded, and the contents of the image will be viewed through the image widget.