JSONStore error when push a collection with documents with files

我是研究僧i 提交于 2019-12-02 09:07:20
cnandreu

"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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!