Progress will discontinue Telerik Platform on May 10th, 2018. Learn more

Using the Low-Level API

Using the Low-Level API

The low-level offline files API allows you to make files available offline in cases where HTML processing is not applicable. Such cases include working with offline files that are not part of the UI or building a UI with non-HTML-based frameworks, among others.

Using the low-level offline files API you can offline-enable either files stored in Telerik Platform or external files from third-party providers.

The general steps for making files available offline are:

  • (online) Identify the files that you want to have offline.
  • (online) Invoke the downloadOffline method for each.
  • (offline) Switch the online URL to the offline URL. You can get the offline URL using the getOfflineLocation method.
  • (offline) Handle the case when a file is not available offline and cannot be downloaded.

Below you will find the available operations relating to offline files. You can also consult the API Reference.

Making a File Available Offline

When you want a file to be available offline, you must request that explicitly so that the SDK can download the file. After you have the file on the device, you can use it instead of the online copy whenever you are offline, but also when you are online to save bandwidth or for improved responsiveness. See Getting the File's Offline URL to learn how to use the device-local copy.

The downloadOffline operation downloads the specified file to the device so that it is available offline. It returns the offline URL of the file in the success callback.

el.offlineStorage.files.downloadOffline(location, overwriteExisting, successFunction, errorFunction);

where location is a file Id if you store the file using Telerik Platform or a HTTP(S) URL if you are passing an external file and overwriteExisting is a Boolean parameter that specifies whether you want the file to be overwritten if it exists. For example:

File stored in Cloud Files:

el.offlineStorage.files.downloadOffline("c473ea70-f7c0-11e4-87db-713680c9d2da", true,
    function(data) {
        alert(JSON.stringify(data));
    },
    function(error) {
        alert(JSON.stringify(error));
    });

File stored externally:

el.offlineStorage.files.downloadOffline("http://images.example.com/img01.jpg", false,
    function(data) {
        alert(JSON.stringify(data));
    },
    function(error) {
        alert(JSON.stringify(error));
    });

Getting the File's Offline URL

When you want to use an offline copy of a file, you need to acquire its local URL using the getOfflineLocation operation. It returns null if the specified file is not available offline.

el.offlineStorage.files.getOfflineLocation(location, successFunction, errorFunction);

where location is a File Id if you store the file using Telerik Platform or a HTTP(S) URL if you are passing an external file.

Checking If the File Exists Offline

You can check if a file already exists offline using the existsOffline operation:

el.offlineStorage.files.existsOffline(location, successFunction, errorFunction);

where location is a File Id if you store the file using Telerik Platform or a HTTP(S) URL if you are passing an external file.

Removing Files from the Offline Store

At some point you may need to physically remove files from the device's offline store. Both purge operations that you can use to do that only delete the file content and mapping data from the offline store. This means that:

  • If you are storing files in Telerik Platform, the file metadata will not be deleted from the offline store. If you need to delete it, use the operations in Managing the Offline Storage.
  • If you are storing files in Telerik Platform, neither the file metadata nor the file content will be deleted from the cloud, even after synchronization.

Removing a Single File from the Offline Store

Use the purge operation to remove a single file from the device's offline store:

el.offlineStorage.files.purge(location, successFunction, errorFunction);

where location is a File Id if you store the file in Telerik Platform or a HTTP(S) URL if you are passing an external file.

Removing All Files from the Offline Store

To remove all files stored on the device at once, use the purgeAll operation:

el.offlineStorage.files.purgeAll(successFunction, errorFunction);

See Also

Start a free trial Request a demo
Contact us: +1-888-365-2779
sales@telerik.com
Copyright © 2016-2017, Progress Software Corporation and/or its subsidiaries or affiliates. All rights reserved.