Downloading Data

This topic describes how your application can download data from a remote server.


Related Info


Samples


Samsung TVs support downloading data from a remote server, using the Download API. For example, you can download external subtitles for a video.

Prerequisites

To use the Download API, the application has to request permission by adding the following privilege to the "config.xml" file:

<tizen:privilege name='http://tizen.org/privilege/download'></tizen:privilege> 

Starting a Download

To download data:

  1. Check that downloading is supported using the getCapability() method of the SystemInfo API:

    var downloadPossible = 
      tizen.systeminfo.getCapability('http://tizen.org/feature/download');
    console.log(downloadPossible);  
    
  2. Create a download request object using the DownloadRequest() method:

    var download_obj = new tizen.DownloadRequest('http://download.tizen.org/tools/README.txt', 'downloads');
    
  3. Start the download using the start() method, with the download request object as a parameter:

        tizen.download.start(download_obj, {
      onprogress: function(id, receivedSize, totalSize) {
        console.log(id);
        console.log(receivedSize);
        console.log(totalSize);
      },
      onpaused: function(id) {
        console.log(id);
      },
      oncanceled: function(id) {
        console.log(id);
      },
      oncompleted: function(id, fullPath) {
        console.log(id);
        console.log(fullPath);
      },
      onfailed: function(id, error) {
        console.log(id);
        console.log(JSON.stringify(error));
      }
    });
    

    When downloading is complete, the oncompleted() event handler fires.