<object>.getBinary

The <object>.getBinary allows downloading and associating binary files with the records in the offline mode. The API downloads the binary files for the specified record primary keys of the object. The downloaded files are read from the device without downloading again from the server (i.e. the binary files can be used in the offline mode).

NOTE: For the <object>.getBinary API to work, ensure the object definition in Quantum Fabric has a defined binary column .

Quantum Visualizer (JavaScript)

NOTE: Not supported for Mobile Web, Windows, and Desktop Web channels.

Signature



<KNYObj>.getBinary (options, fileDownloadStartedCallback, chunkDownloadCompletedCallback, streamDownloadCompletedCallback, fileDownloadCompletedCallback, downloadFailureCallback)

Parameters

Parameter Type Description Required
options JSON A dictionary containing binaryColumnName, forceDownload, chunkSize, and primaryKeys. Yes
fileDownloadStartedCallback Function The function is invoked when the download starts. Response object includes fileId. Yes
chunkDownloadCompletedCallback Function Not support in the current version. Yes
streamDownloadCompletedCallback Function Not supported in the current version Yes
fileDownloadCompletedCallback Function The function is invoked when the file is downloaded successfully. Response Object includes fileId and filePath. Yes
downloadFailureCallback Function The function is invoked when the file download fails with a cause of failure. Response object will have the exception for failure. Yes

Sync Options

Key Type Description Required
columnName String Name of the binary column for which the data must be downloaded. Yes
forceDownload Boolean Enable the flag to forcefully download a file from the server. If the flag is not enabled and the file is available on the device, it returns the local file. No
fileId String

Downloaded files are saved with the current time stamp as the file name, if fileId is given, the ID is appended to the timestamp.

Example: 1521455068827_<fileID>

No
primaryKeys JSON Specify the primary keys of the record to be updated. Use a record's primary key, column name as the key and respective values to populate the primary keys JSON. Yes
chunkSize Number Not supported in the current version. No

Return Type

void

Example

var media = new kony.sdk.KNYObj("media");
var options = {};
options.primaryKeys = {
    "id": "2"
};
options.columnName = "picture";
options.fileId = "pic1";

function onFileDownloadStartedApp(response) {
    kony.print("Object onFileDownloadStarted" + JSON.stringify(response));
}

function onStreamDownloadCompletedApp(response) {
    //Not Supported in the current version
}

function onChunkDownloadCompletedApp(response) {
    //Not Supported in the current version
}

function onFileDownloadCompletedApp(response) {
    kony.print("Object onFileDownloadCompleted" + JSON.stringify(response) + ", file path = " + response.filePath);
}

function onDownloadFailureApp(error) {
    kony.print("Object onDownloadFailure:" + JSON.stringify(error));
}
media.getBinary(options, onFileDownloadStartedApp, onStreamDownloadCompletedApp,
    onChunkDownloadCompletedApp, onFileDownloadCompletedApp, onDownloadFailureApp);
}

Android (Java)

Signature

void getBinary(final Map<String, Object> options, final KNYBinaryDownloadCallback knyBinaryDownloadCallback)

Parameters

Parameter Type Description Required
options HashMap<String, Object> A dictionary containing binaryColumnName, forceDownload, chunkSize, and primaryKeys. Yes
knyBinaryDownloadCallback KNYBinaryDownloadCallback Application implements onFileDownloadStarted, onStreamDownloadCompleted, onChunkDownloadCompleted, onFileDownloadCompleted, onDownloadFailure methods of KNYBinaryDownloadCallback interface. Yes

 

Sync Options

Key Type Description Required
columnName String Name of the binary column for which data is to be download. Yes
forceDownload Boolean Enable this flag to forcefully download the file from the server. If the flag is not enabled and the file is available on the device, it returns the local file. No
fileID String The ID of the file downloaded. The ID is appended with a timestamp. No
primaryKeys Hashmap<String, Object> Specify the primary keys of the record to be updated. Use a record's primary key, column name as the key and respective values to populate the primary keys map. Yes
chunkSize Integer Not supported in the current version. No

Return Type

void

Example

KNYObj media = new KNYObj("media");
HashMap < String, Object > options = new HashMap < String, Object > ();
HashMap < String, Object > primaryKeys = new HashMap < > ();
primaryKeys.put("id", 2);
options.put(KSPublicConstants.PRIMARY_KEYS, primaryKeys);
options.put(KSPublicConstants.BINARY_COLUMN_NAME, "picture");
options.put(KSPublicConstants.BINARY_FORCE_DOWNLOAD, false);
options.put(BinaryDataManagerConstants.FILE_ID, "pic1");
syncObject.getBinary(options, new KNYBinaryDownloadCallback() {
    @Override
    public void onFileDownloadStarted(Object object) {
        Log.d("getBinary", "File download started");
    }

    @Override
    public void onStreamDownloadCompleted(Object object) {
        //Not supported in the current version
    }

    @Override
    public void onChunkDownloadCompleted(Object object) {
        //Not supported in the current version
    }

    @Override
    public void onFileDownloadCompleted(Object object) {
        Log.d("getBinary", "File download completed successfully");
    }

    @Override
    public void onDownloadFailure(Object error) {
        Log.e("getBinary", "File download failed with error :" + error.toString());
    }
});

iOS (Objective C)

Signature

void <KNYObj>.getBinary:(NSDictionary <NSString *,id>*)options
	 downloadStartedHandler:(KNYFileDownloadStartedCompletionBlock)fileDownloadStartedCompletionBlock
	 chunkDownloadCompletedHandler:(KNYChunkDownloadCompletedCompletionBlock)chunkDownloadCompletedCompletionBlock
	 streamDownloadCompletedHandler:(KNYStreamDownloadCompletedCompletionBlock)streamDownloadCompletionBlock
	 fileDownloadCompletedHandler:(KNYFileDownloadCompletedCompletionBlock)fileDownloadCompletedCompletionBlock
	 downloadFailureHandler:(KNYDownloadFailureCompletionBlock)downloadFailureCompletionBlock)

Parameters

Parameter Type Description Required
options NSDictionary<NSString*, id> A dictionary containing binaryColumnName, forceDownload, chunkSize, and primaryKeys. Yes
fileDownloadStartedHandler KNYFileDownloadStartedCompletionBlock The function is invoked when the download has started. Response object includes fileId. Yes
chunkDownloadCompletedHandler KNYChunkDownloadCompletedCompletionBlock Not supported in the current version. Yes
streamDownloadCompletedHandler KNYStreamDownloadCompletedCompletionBlock Not supported in the current version

Yes

fileDownloadCompletedHandler KNYFileDownloadCompletedCompletionBlock The function is invoked when the file is downloaded successfully. Response Object includes fileId and filePath. Yes
downloadFailureHandler KNYDownloadFailureCompletionBlock The function is invoked when the file download fails with the cause of failure. Response object will have the exception for failure. Yes

Sync Options

Key Type Description Required
columnName String Name of the binary column for which the data is to be downloaded. Yes
forceDownload Boolean Enable this flag to forcefully download the file from the server. If the flag is not enabled and the file is available on the device, it returns the local file. No
fileID String The ID of the file downloaded. The ID is appended with a timestamp. No
primaryKeys NSDictionary<NSString *, id> Specify the primary keys of the record to be updated. Use a record's primary key, column name as the key and respective values to populate the primary keys dictionary. Yes
chunkSize Integer Not supported in the current version. No

Return Type

void

Examples

KNYObj * _media = [
    [KNYObj alloc] initWithName: @"media"
    error: & ;error
];
NSMutableDictionary < NSString * , id > * options = [
    [NSMutableDictionary alloc] init
];
NSMutableDictionary < NSString * , id > * primaryKeys = [
    [NSMutableDictionary alloc] init
];

primaryKeys[@"id"] = @"2";
options[KNYCONSTANTS_CRUD_OPTION_PRIMARY_KEYS] = primaryKeys;
options[KNYCONSTANTS_BINARY_COLUMN_NAME] = @"picture";
options[KNYCONSTANTS_BINARY_FORCE_DOWNLOAD] = @NO;
options[KNYCONSTANTS_BINARY_FILEID] = @"pic1";
NSMutableArray < NSString * > * filePaths = [NSMutableArray new];

[media getBinary: options downloadStartedHandler: ^ (id object) {
        NSLog(@"Download started successfully");
    }
    chunkDownloadCompletedHandler: ^ (id object) {
        //Not implemented
    }
    streamDownloadCompletedHandler: ^ (id object) {
        //Not implemented
    }
    fileDownloadCompletedHandler: ^ (id object) {
        NSLog(@"Download completed successfully");
    }
    downloadFailureHandler: ^ (id object) {
        id error = [object valueForKey: KNYCONSTANTS_SYNC_ERRORS];
        NSLog(@"Update failed with error: %@", [error value]);
    }
];

NOTE: Binary download support through Offline Objects is limited in RDBMS, Storage and SAP backend services.