locker.download
  • 06 Mar 2021
  • 1 Minute to read
  • Contributors
  • Dark
    Light
  • PDF

locker.download

  • Dark
    Light
  • PDF

Article summary

Description

Initiates an asynchronous download of a specified resource from your app's locker.

When downloading completes, the resource is stored inside the runtime's cache object using the resource's locker token as a key. An alternative key can be specified, if desired.

The Ux.ResourceReady event is triggered so you can take action when your resource becomes available.


Input Parameters

NameTypeRequiredDescription
tokenTextYesResource's locker token
[key]TextNoUnique cache key where resource will be stored; Default = resource's locker token
[type]TextNoType of data being downloaded

The following types are supported:

NameDescription
textPlain text (default)
jsonJson object
xmlXml document
imagePlatform-specific image object
bitsRaw binary data

Returns

No return value.


Examples

// inside the Ux.Initialize script...
// download resource from app's locker
app.locker.download("TOKEN");
// inside the Ux.Initialize script...
// download resource from app's locker, specifying a custom cache key
app.locker.download("TOKEN", "config");
// inside the Ux.ResourceReady script...
// note: this script will run once for each downloaded resource
// note: demonstrates how to take action immediately after download completes

// get the cache key for this downloaded resource
var key = script.args[0];

// fetch the downloaded resource from cache
var item = cache.get(key);
// inside any script (i.e. Ux.Change)...
// note: demonstrates how to manually check for resource anytime

// check if resource is available
if (cache.exists("TOKEN") === true)
    debug.log("Resource exists.");

Remarks

Use this function when you need to download resources from your app's locker such as files, configurations, lookup tables, raw data, or images.

Downloading resources from your app's locker instead of the open Internet is strongly recommended since they are fully managed by the app platform.

One common scenario is to download a file using the Ux.Initialize event. Once downloaded, you can take action using the Ux.ResourceReady event. The cache key you provided is accessible via the runtime's script object.

Two-Step Process

Downloading resources can be slow based on connection speeds and the size of the resources being downloaded.

Because of this speed issue, downloading resources requires a two-step process. First, you must initiate the download (from one script). Second, you take action (if needed) after the download completes from another script (i.e. Ux.ResourceReady).

By separating these steps, the user's experience remains fluid. Otherwise, the user interface would freeze until the download completes, resulting in a poor user experience.


What's Next