Commit 9853d53e authored by Xiaowu Zhang's avatar Xiaowu Zhang

fix big data storage problem

parent f976d3de
...@@ -595,64 +595,58 @@ ...@@ -595,64 +595,58 @@
transaction, transaction,
global_db, global_db,
BlobInfo, BlobInfo,
digest,
readResult; readResult;
new RSVP.Queue() jIO.util.readBlobAsArrayBuffer(metadata._blob)
.push(jIO.util.readBlobAsText(metadata._blob). .then(function (event) {
then(function (e) { readResult = event.target.result;
digest = jIO.util.makeBinaryStringDigest(e.target.result); //xxx BlobInfo = {
readResult = e.target.result; "content_type": metadata._blob.type,
BlobInfo = { "length": metadata._blob.size
"content_type": metadata._blob.type, };
"digest": digest, new RSVP.Queue()
"length": metadata._blob.size
};
}, function () {
command.error("conflict", "broken blob",
"Cannot read data to put");
}))
.push(function () { .push(function () {
return openIndexedDB(jio_storage._database_name); return openIndexedDB(jio_storage._database_name);
}) })
.push(function (db) { .push(function (db) {
global_db = db; global_db = db;
transaction = db.transaction(["attachment", transaction = db.transaction(["attachment",
"blob"], "readwrite"); "blob"], "readwrite");
return promiseResearch(transaction, metadata._id, "attachment", "_id"); return promiseResearch(transaction,
}) metadata._id, "attachment", "_id");
})
.push(function (researchResult) { .push(function (researchResult) {
if (researchResult.result === undefined) { if (researchResult.result === undefined) {
throw ({"status": 404, "reason": "Not Found", throw ({"status": 404, "reason": "Not Found",
"message": "indexeddbStorage unable to put attachment"}); "message": "indexeddbStorage unable to put attachment"});
} }
//update attachment //update attachment
researchResult.result._attachment = researchResult.result._attachment researchResult.result._attachment = researchResult.
|| {}; result._attachment || {};
researchResult.result._attachment[metadata._attachment] = researchResult.result._attachment[metadata._attachment] =
(BlobInfo === undefined) ? "BlobInfo" : BlobInfo; (BlobInfo === undefined) ? "BlobInfo" : BlobInfo;
return putIndexedDB(researchResult.store, researchResult.result); return putIndexedDB(researchResult.store, researchResult.result);
}) })
.push(function () { .push(function () {
//put in blob //put in blob
var store = transaction.objectStore("blob"); var store = transaction.objectStore("blob");
return putIndexedDB(store, {"_id": metadata._id, return putIndexedDB(store, {"_id": metadata._id,
"_attachment" : metadata._attachment, "_attachment" : metadata._attachment,
"blob": metadata._blob}, readResult); "blob": metadata._blob}, readResult);
}) }).push(function () {
.push(function () { return {"status": 204};
return ({"digest": digest}); //xxx })
}) .push(undefined, function (error) {
.push(undefined, function (error) {
// Check if transaction is ongoing, if so, abort it // Check if transaction is ongoing, if so, abort it
if (transaction !== undefined) { if (transaction !== undefined) {
transaction.abort(); transaction.abort();
} }
if (global_db !== undefined) { if (global_db !== undefined) {
global_db.close(); global_db.close();
} }
throw error; throw error;
}) })
.push(command.success, command.error, command.notify); .push(command.success, command.error, command.notify);
});
}; };
...@@ -688,7 +682,7 @@ ...@@ -688,7 +682,7 @@
}) })
.push(function (result) { .push(function (result) {
//get data //get data
if (typeof result.blob === "string") { if (result.blob.byteLength !== undefined) {
result.blob = new Blob([result.blob], result.blob = new Blob([result.blob],
{type: "text/plain"}); {type: "text/plain"});
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment