javascript - Can't save blob to indexedDB -


i'm having trouble saving blob in indexeddb, , blob.
if save else (like image base64), works fine.
blob, there empty object property saved.

screenshot console:

enter image description here

code:

//prepared blob... var openrequest = indexeddb.open("testdb",1);  openrequest.onupgradeneeded = function(e) {     var thisdb = e.target.result;      if(!thisdb.objectstorenames.contains("stash")) {         thisdb.createobjectstore("stash");     } }  openrequest.onsuccess = function(e) {     db = e.target.result;      var transaction = db.transaction(["stash"],"readwrite");     var store = transaction.objectstore("stash");     var tid = date.now();      var obj = {         bl:blob,         created:tid     }     console.log(obj);     //add      var request = store.add(obj, tid);     request.onerror = function(e) {         console.log("error",e.target.error.name);     }     request.onsuccess = function(e) {         console.log("success");     } } openrequest.onerror = function(e) {     //.... } 

i tried save blob (not wrapped obj property), it's same.
can save blob hdd, , if console log obj, get:

enter image description here

so guess, blob valid, , problem in adding indexeddb. i'm new blob/indexeddb, , doing noob mistake.

can please advise, doing wrong?

ps: no error messages @ all

you can convert blob or file object arraybuffer object or binarystring , save it. convert blob after read indexeddb.

//prepared blob... blobtoblob2(blob, saveblob2);  function blobtoblob2(blob, callback){     var reader = new filereader();     reader.readasarraybuffer(blob);     reader.onload = function(e) {         callback({             buffer: e.target.result,             type: blob.type         });     }; }  function blob2toblob(blob2){     return new blob([blob2.buffer],{type:blob2.type}); }  function saveblob2(blob2){     //..... code     var obj = {         bl:blob2,         created:tid     }     var request = store.add(obj, tid);     //..... code } 

Comments

Popular posts from this blog

node.js - Using Node without global install -

How to access a php class file from PHPFox framework into javascript code written in simple HTML file? -

java - Null response to php query in android, even though php works properly -