JSONStore error when push a collection with documents with files

后端 未结 1 1738
不思量自难忘°
不思量自难忘° 2021-01-26 05:10

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

相关标签:
1条回答
  • 2021-01-26 05:37

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

    0 讨论(0)
提交回复
热议问题