Page tree
Skip to end of metadata
Go to start of metadata

This API initiates a download from a file in the Integrated File System (IFS) to the browser. 

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 for details on how to create a PUIDNLEXIT 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.
  • inline (optional) - This controls how the content is delivered. If set to true, a new browser window/tab will be opened with the intention of displaying the downloaded content in that tab (if the browser supports it). If set to false (which is the default), the data will be sent as a download, and the user will be prompted to save it to disk or open it in another application.
  • 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:

The following example downloads a PDF file from the /usr/share/accounting directory of the IFS. The user will be prompted to save this document to disk, because it was not specified as "inline":

pui.download({ "id":  "/usr/share/accounting/invoice12345.pdf" });

This example downloads a product image to be displayed in a new window in the browser:

pui.download({ "id":  "/images/products/54321.jpg", "inline": true, "contentType": "image/jpeg" });

This example passes "itemrpt" to the PUIDNLEXIT program. PUIDNLEXIT will have code in it to look for the "itemrpt" string, and then will generate a PDF of an item report, store it in a temporary file, and download it to be displayed in the browser. After the download is complete, PUIDNLEXIT will delete the temporary file. (Most of the needed logic is in the download program. See PUIDNLEXIT for details.)

pui.download({ "id":  "itemrpt", "inline": true, "contentType": "application/pdf" });

Inline Usage

To perform a download so that it specifies a URL to be used as an "image source" or similar, see the pui.downloadURL() API