Downloading Files

Downloading Files

The download operation allows you to download files to the user device. Where direct downloading is not supported, you can acquire the file download URL using an alternative SDK method.

Download Files in Cordova Hybrid Apps

The Files.download method wraps the Apache Cordova download() FileTransfer API function. It allows you to download files stored in Telerik Platform by ID. To use it, ensure that the File Transfer plugin is enabled in your Apache Cordova project.

var fileToDownload = 'b1c607f3-36a4-11e5-8a45-a77601c4083d';
var pathOnDevice = 'cdvfile://localhost/persistent/path/to/folder/list.txt';
el.files.download(fileToDownload, pathOnDevice)
    .then(function() {
        // the file has been downloaded to the target location
    }, function(err) {
        // handle any errors that might have occurred during download
    });

For details on using the cdvfile protocol for specifying file paths, see the Cordova File Plugin documentation.

Download Files in Non-Cordova Apps

In JavaScript frameworks such as NativeScript or Node.js you can use the getDownloadUrlById() method to acquire the location (URL) of a file stored in Telerik Platform based on its ID. With the file location at hand, you need to utilize the framework's own tools to handle the download.

For example, in a web application you can display or download files by setting their download URLs to HTML tag attributes:

<script>
    var el = new Everlive('your-app-id');
    var fileId; // the file identifier is retrived from the RESTful services
    el.files.getDownloadUrlById(fileId)
    .then(function(downloadUrl){
        document.getElementById('anchor1').href = downloadUrl;
    },
    function(error){
        alert(JSON.stringify(error));
    });
</script>
<a id="anchor1">Open file</a>

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.