Created
February 19, 2016 19:36
-
-
Save xMartin/cac25bdddf943179badb to your computer and use it in GitHub Desktop.
crypto-pouch binary attachments
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
<!DOCTYPE html> | |
<script src="node_modules/pouchdb/dist/pouchdb.js"></script> | |
<script src="node_modules/crypto-pouch/bundle.js"></script> | |
<script> | |
var db = new PouchDB('db') | |
PouchDB.plugin(crypto) | |
var id = 'id-' + PouchDB.utils.uuid() | |
db.crypto('secretSecureEncryptionKey') | |
.then(function () { | |
var attachment = new Blob(['Is there life on Mars?'], {type: 'text/plain'}); | |
return db.put({ | |
_id: id, | |
_attachments: { | |
'att.txt': { | |
content_type: 'text/plain', | |
data: attachment | |
} | |
} | |
}) | |
}) | |
.then(function () { | |
return db.get(id, { | |
attachments: true, | |
binary: true | |
}).then(function (doc) { return doc._attachments['att.txt'].data}) | |
}) | |
.catch(function (error) { | |
console.log('\n db1: error ==============================') | |
console.log(error) | |
}) | |
.then(function (doc) { | |
console.log('\ndb1: doc created ==============================') | |
console.log(doc) | |
}) | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment