I have a JSONStore for a list of customers, the user can add documents to those customers using the app.
The list of cusotmers and its data (also attached documents) mus
"Don't store blobs [...] in your database. Store identifiers in your database and put the blobs as files onto the storage." - Source
Cordova has a File API you can use.
Here's a quick example:
//Code to write customer-1-file1.ppt and customer-1-file2.ppt to disk.
//See Cordova's File API.
//Pseudocode to get the blobsCollection and add metadata to be able to find the files.
//This would be inside the success callback for writing the files.
WL.JSONStore.get('blobsCollection')
.add([{fileName: 'customer-1-file1.ppt'}, {fileName: 'customer-1-file2.ppt'}]);
//Some time has passed...
//Pseudocode to get %customer-1% from disk
//% are wildcards characters and match any string
WL.JSONStore.get('blobsCollection')
.find({fileName: 'customer-1'}, {exact: false})
.then(function (listOfFiles) {
//listOfFiles => [{_id: 1, json: { fileName: 'customer-1-file1.ppt'} },
// {_id: 2, json: { {fileName: 'customer-1-file2.ppt'} }]
var firstFile = listOfFiles[0].json.fileName;
//Code to read firstFile. See Cordova's File API.
});
JSONStore is backed by SQLite (well, technically SQLCipher which is a wrapper for SQLite that adds data encryption). Read Internal Versus External BLOBs in SQLite. The takeaway is "For BLOBs smaller than 100KB, reads are faster when the BLOBs are stored directly in the database file. For BLOBs larger than 100KB, reads from a separate file are faster".
If you need to store blobs bigger than the default SQLite Cursor size (1048576 bytes), I suggest a feature request here.
I'll make sure this is mentioned in the documentation.
Note that there's a getPushRequired API you can use to get the list of documents that the push
API will try to send to the Worklight Adapter. You will need to send file changes yourself to the Worklight Adapter using WL.Client.invokeProcedure
, or directly to a backend using something like jQuery.ajax
.