簡體   English   中英

推送包含文件的文檔時出現JSONStore錯誤

[英]JSONStore error when push a collection with documents with files

我有一個用於存儲客戶列表的JSONStore,用戶可以使用該應用向這些客戶添加文檔。

監控程序列表及其數據(以及隨附的文檔)必須與后端同步。

當我將ppt文檔774KB(即二進制文件的大小,將其轉換為base64)添加到json存儲並執行push()時,它將失敗,並顯示以下錯誤:

E/CursorWindow(32705): need to grow: mSize = 1048576, size = 1056310, freeSpace() = 1048464, numRows = 1
E/CursorWindow(32705): Attempting to grow window beyond max size (1048576)
E/Cursor(32705): Failed allocating 1056310 bytes for text/blob at 0,1
D/Cursor(32705): finish_program_and_get_row_count row 0
E/CursorWindow(32705): need to grow: mSize = 1048576, size = 1056310, freeSpace() = 1048464, numRows = 1
E/CursorWindow(32705): Attempting to grow window beyond max size (1048576)
E/Cursor(32705): Failed allocating 1056310 bytes for text/blob at 0,1
D/Cursor(32705): finish_program_and_get_row_count row 0
E/CursorWindow(32705): Bad request for field slot 0,0. numRows = 0, numColumns = 4
E/jsonstore-core(32705): error while dispatching action "allDirty"
E/jsonstore-core(32705): java.lang.IllegalStateException: get field slot from row 0 col 0 failed
E/jsonstore-core(32705):    at net.sqlcipher.CursorWindow.getLong_native(Native Method)
E/jsonstore-core(32705):    at net.sqlcipher.CursorWindow.getLong(CursorWindow.java:381)
E/jsonstore-core(32705):    at net.sqlcipher.AbstractWindowedCursor.getLong(AbstractWindowedCursor.java:110)
E/jsonstore-core(32705):    at net.sqlcipher.AbstractCursor.moveToPosition(AbstractCursor.java:195)
E/jsonstore-core(32705):    at net.sqlcipher.AbstractCursor.moveToNext(AbstractCursor.java:257)
E/jsonstore-core(32705):    at android.database.CursorWrapper.moveToNext(CursorWrapper.java:166)
E/jsonstore-core(32705):    at com.worklight.androidgap.plugin.storage.AllDirtyActionDispatcher$AllDirtyAction.performAction(AllDirtyActionDispatcher.java:148)
E/jsonstore-core(32705):    at com.worklight.androidgap.plugin.storage.AllDirtyActionDispatcher$AllDirtyAction.performAction(AllDirtyActionDispatcher.java:119)
E/jsonstore-core(32705):    at com.worklight.androidgap.plugin.storage.DatabaseActionDispatcher$Context.performReadableDatabaseAction(DatabaseActionDispatcher.java:141)
E/jsonstore-core(32705):    at com.worklight.androidgap.plugin.storage.AllDirtyActionDispatcher.dispatch(AllDirtyActionDispatcher.java:64)
E/jsonstore-core(32705):    at com.worklight.androidgap.plugin.storage.DatabaseActionDispatcher.dispatch(DatabaseActionDispatcher.java:56)
E/jsonstore-core(32705):    at com.worklight.androidgap.plugin.storage.BaseActionDispatcher.dispatch(BaseActionDispatcher.java:87)
E/jsonstore-core(32705):    at com.worklight.androidgap.plugin.storage.DispatchingPlugin$ActionDispatcherRunnable.run(DispatchingPlugin.java:113)
E/jsonstore-core(32705):    at com.worklight.androidgap.plugin.storage.DispatchingPlugin$SerialExecutor$1.run(DispatchingPlugin.java:147)
E/jsonstore-core(32705):    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
E/jsonstore-core(32705):    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
E/jsonstore-core(32705):    at java.lang.Thread.run(Thread.java:856)
E/myApp (32705): [wl.jsonstore] {"src":"push","err":8,"msg":"FAILED_TO_GET_UNPUSHED_DOCUMENTS_FROM_DB","col":"Documentos","usr":"jsonstore","doc":{},"res":{}}

我可以添加文檔,錯誤是執行push()方法。

我在stackoverflow和信息中心中看到的有關JSONStore的所有信息是,沒有大小限制。 我的手機有足夠的可用空間。

任何想法?

謝謝。

“不要將blob存儲在數據庫中。將標識符存儲在數據庫中,並將blob作為文件放置到存儲中。” - 來源

Cordova有一個可以使用的File API

這是一個簡單的示例:

//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由SQLite支持(技術上來說SQLCipher是SQLite的包裝器,用於添加數據加密)。 在SQLite中讀取內部與外部BLOB 要點是“對於小於100KB的BLOB,將BLOB直接存儲在數據庫文件中時讀取速度更快。對於大於100KB的BLOB,從單獨文件中讀取速度更快 ”。

如果您需要存儲大於默認SQLite游標大小(1048576字節)的Blob,建議在此處提出功能請求

我將確保在文檔中對此進行提及。

請注意,有一個getPushRequired API,您可以使用它來獲取push API將嘗試發送到Worklight Adapter的文檔列表。 您將需要使用WL.Client.invokeProcedure自己將文件更改發送到Worklight適配器,或者使用jQuery.ajax類的文件直接發送到后端。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM