當我將一個圖像(2-3mb base64字符串)添加到我的索引數據庫中時,它似乎與從iPad/Safari使用Web應用程序時崩潰(在Chrome桌面上正常工作)。IndexedDB在添加記錄時崩潰圖像
InvalidStateError (DOM IDBDatabase Exception 11): Failed to execute 'transaction' on 'IDBDatabase': The database connection is closing.
對象試圖插入:
{
categoryNo: "C0103"
imageData: [{base64Image: "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAASABIAAD…aUOUbIHsTUsVwQRZJF8/94dMe9TxKzK7ugwhK1s4su8T/2Q==",
imageUploaded: false
}
我使用IndexedDB的存儲字符串,它工作正常,只是當我嘗試添加的對象,與以base64圖像。
bcUpdateIDB: function(sInspectionNo, sLineNo, sCategory, oRecord){
var oController = this;
var objectStore = oController.myDB.transaction("imageDB").objectStore("imageDB");
var items = [];
objectStore.openCursor().onsuccess = function(event) {
var cursor = event.target.result;
if (cursor) {
items.push(cursor.value);
cursor.continue();
} else {
dataRecords = items;
var oTransaction = oController.myDB.transaction(["imageDB"], "readwrite");
var oDataStore = oTransaction.objectStore("imageDB");
var recordFound = false;
for (var i=0; i<dataRecords.length;i++){
var oDataRecord = dataRecords[i];
if(oDataRecord.lineNo === sLineNo && oDataRecord.inspectionNo === sInspectionNo && oDataRecord.category === sCategory){
recordFound = true;
oDataStore.delete(oDataRecord.id);
if(oRecord.imageData.length > 0){
oDataStore.add(oRecord);
}
}
}
if(!recordFound){
oDataStore.add(oRecord);
}
}
};
在Safari中它似乎掛在'.add()',這在Chrome中有效。此外,其他添加/刪除操作對另一個事務工作正常。
你應該能夠存儲blob和文件,以及更好。 – Endless