Last active
August 29, 2015 14:04
-
-
Save sTiLL-iLL/de650e055fa0e42429de to your computer and use it in GitHub Desktop.
blobs in the IndexDB
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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