Skip to content

Instantly share code, notes, and snippets.

@sTiLL-iLL
Last active August 29, 2015 14:04
Show Gist options
  • Save sTiLL-iLL/de650e055fa0e42429de to your computer and use it in GitHub Desktop.
Save sTiLL-iLL/de650e055fa0e42429de to your computer and use it in GitHub Desktop.
blobs in the IndexDB
// make a blob
var blob = new Blob(['blobyJo'], {
type: 'text/plain'
});
try {
var store = db.transaction(['buckets'], 'readwrite')
.objectStore('buckets');
var fngr = store.put(blob, 'blob');
fngr.onerror = function(err) {
console.log(err);
};
fngr.onsuccess = function(event) {
console.log('blob as blob'); // NO base64 conversion needed!!!
};
}
catch (err) {
var rdr = new FileReader();
rdr.onload = function(event) {
var store = db.transaction(['buckets'], 'readwrite')
.objectStore('buckets');
var dta = event.target.result,
fngr = store.put(dta, 'blob');
fngr.onerror = function(err) {
console.log(err);
};
fngr.onsuccess = function(event) {
console.log('blob as b64');
};
};
rdr.readAsDataURL(blob);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment