Sync ORM API Guide: Download APIs

Large Binary Objects

The Large Binary Objects API allows you to retrieve and delete large binary objects, schedule a download, and get the location of the objects. While the Sync Chunking Mechanism applies to all of sync, the Large Binary Objects API supports the download of binary data stored in a particular object in multiple chunks. The download occurs in the background, allowing the user to perform tasks simultaneously.

The APIs in this section are part of the sync namespace.

Download APIs

The following APIs support the download of binary data. The getBinary method provides the end-to-end functionality for the Large Binary Object feature. The other methods are provided to enable finer control to the user. For example, these methods allow the user to schedule and trigger the download based on his/her requirements.

getBinary

The getBinary API returns the file path to the binary file on the local device. If the binary data doesn’t exist on the local device, it downloads the binary data from the backend data source, writes it to the local storage, and then returns the binary data file path.

Syntax:

sync.getBinary(tableName, binaryColumnName, primaryKeyTable, config, successCallback, errorCallback)

Parameters:

Name Type Description
tableName string Name of the table
binaryColumnName string Name of the binary column
primaryKeyTable key/value pair Table of key/value pairs that uniquely identify the record.
config key/value pair Key/value pairs that contain configurable properties required for the download operation.
successCallback function Handle to function that is invoked after the method is executed successfully.
errorCallback function Handle to function that is invoked if the method errors out.

 

Example:

var primaryKeyTable = {};
primaryKeyTable.name = “abcd”;
var downloadConfig = {};
downloadConfig.ChunkSize = 100000;

function successCallback(result){
     kony.print("Successful download with result : “+JSON.stringify(result);
}

function errorCallback(err){
     kony.print("Error in downloading file : "+JSON.stringify(err));
}

sync.getBinary("media", "url", primaryKeyTable, downloadConfig, successCallback, errorCallback);  

createDownloadTask

The createDownloadTask API creates a binary data download task which can be scheduled for operation whenever user requires.

Syntax:

sync.createDownloadTask(tableName, binaryColumnName, primaryKeyTable, config, successCallback, errorCallback)

Parameters:

Name Type Description
tableName string Name of the table
binaryColumnName string Name of the binary column
primaryKeyTable key/value pair Table of key/value pairs that uniquely identify the record
config key/value pair Key/value pairs that contain configurable properties required for the download operation.
successCallback function Handle to function that is invoked after the method is executed successfully.
errorCallback function Handle to function that is invoked if the method errors out.

 

Example:

var primaryKeyTable = {};
primaryKeyTable.name = “abcd”;
var downloadConfig = {};
downloadConfig.ChunkSize = 100000;

function successCallback(result){
     kony.print("Download task successfully created : “+JSON.stringify(result);
}

function errorCallback(err){
     kony.print("Error in creating download task : "+JSON.stringify(err));
}

sync.createDownloadTask("media", "url", primaryKeyTable, downloadConfig, successCallback, errorCallback);

Note: The createDownloadTask API is deprecated.

startDownload

The startDownload API schedules and executes the download operation.

Syntax:

sync.startDownload(blobID, successCallback, errorCallback)

Parameters:

Name Type Description
blobID string The id which uniquely identifies the binary record. This ID is generated by the createDownloadTask API.
successCallback function Handle to function that is invoked after the download operation is executed successfully.
errorCallback function Handle to function that is invoked if the method errors out.

 

Example:

function successCallback(result){
     kony.print("Successful download with result : “+JSON.stringify(result);
}

function errorCallback(err){
     kony.print("Error in downloading file : "+JSON.stringify(err));
}

sync.startDownload(blobID, successCallback, errorCallback);  

 

pauseDownload

The pauseDownload API pauses the current download operation.

Syntax:

sync.pauseDownload(blobID, successCallback, errorCallback)

Parameters:

Name Type Description
blobID string The id which uniquely identifies the binary record. This ID is generated by the createDownloadTask API.
successCallback function Handle to function that is invoked after the pause operation is executed successfully.
errorCallback function Handle to function that is invoked if the method errors out.

 

Example:

function successCallback(result){
     kony.print("Successful pause with result : “+JSON.stringify(result);
}

function errorCallback(err){
     kony.print("Error in pausing download: "+JSON.stringify(err));
}

sync.pauseDownload(blobID, successCallback, errorCallback);  

 

resumeDownload

The resumeDownload API resumes the current paused download operation.

Syntax:

sync.resumeDownload(blobID, successCallback, errorCallback)

Parameters:

Name Type Description
blobID string The id which uniquely identifies the binary record. This ID is generated by the createDownloadTask API.
successCallback function Handle to function that is invoked after the resume operation is executed successfully.
errorCallback function Handle to function that is invoked if the method errors out.

 

Example:

function successCallback(result){
     kony.print("Successful resume with result : “+JSON.stringify(result);
}

function errorCallback(err){
     kony.print("Error in resuming download of file : "+JSON.stringify(err));
}

sync.resumeDownload(blobID, successCallback, errorCallback);  

 

 

getBinaryDataForPath

The getBinaryDataForPath API returns the file path for the binary data. This API doesn’t download the binary record if it is not available in local storage.

Syntax:

sync.getBinaryDataFilePath(tableName, binaryColumnName, primaryKeyTable, successCallback, errorCallback)

Parameters:

Name Type Description
tableName string Name of the table
binaryColumnName string Name of the binary column
primaryKeyTable key/value pairs Key/value pairs that uniquely identify the record
successCallback function Handle to function that is invoked after the method is executed successfully.
errorCallback function Handle to function that is invoked if the method errors out.

 

Example:

function successCallback(filepath){
     kony.print("File path recieved : "+filepath.FilePath);
}

function errorCallback(primaryKeys){
     alert("File path couldn't be retrieved for primary keys : "+JSON.stringify(primaryKeys));
}

var primaryKeyTable = {};
primaryKeyTable.name = "BIN20160926150752"
sync.getBinaryDataFilePath("media", "url", primaryKeyTable, successCallback, errorCallback);

Note: The getBinaryDataFilePath API is deprecated.

Delete APIs

The following API supports deleting binary data.

deleteBinaryObject

The deleteBinaryObject API deletes the binary object from the server.

Syntax:

sync.deleteBinaryObject(binaryTableName, binaryColumnName, pkTable, options, successCB, errorCB)

Parameters:

Name Type Description
binaryTableName string Name of the table
binaryColumnName string Name of the binary column
pkTable key/value pairs The table of key/value pairs that uniquely identify the record
options string Additional information needed to implement this function.
successCB function Handle to the function that is invoked after the method is executed successfully.
errorCB function Handle to the function that is invoked if the method errors out.

 

Example

function deleteBinaryObject() {
    function successCB(response) {
        kony.print("Success Callback response from deleteBinaryObject ",response);
    }
  
    function errorCB(error) {
        kony.print("Error callback response from deleteBinaryObject ", error);
    }
                
    var binaryTableName="<binary_table_name>";
    var binaryColumnName="<binary_column_name>";
                
    var pkTable = {};
    pkTable.name = "<primary_key>";
                
    var options={};
    options.shouldDeleteBeforeSyncSession=<boolean_value>; //delete policy
                
    sync.deleteBinaryObject(binaryTableName, binaryColumnName, pkTable, options, successCB, errorCB);
}
Copyright © 2013 Kony, Inc. All rights reserved.