calvinmetcalf / crypto-pouch

plugin for encrypted pouchdb/couchdb databases
MIT License
243 stars 43 forks source link

getAttachment not working once crypto is initiated #11

Closed victorpease closed 9 years ago

victorpease commented 9 years ago

getAttachment returns missing doc error once the encryption is activated. As a workaround, i am using the attachments:true option to get the attachments.

calvinmetcalf commented 9 years ago

Yeah it's not supported at the moment

On Thu, Oct 1, 2015, 3:08 PM Víctor Manuel Pease Solano < notifications@github.com> wrote:

getAttachment returns missing doc error once the encryption is activated.

— Reply to this email directly or view it on GitHub https://github.com/calvinmetcalf/crypto-pouch/issues/11.

victorpease commented 9 years ago

this is my alternative getAttach:

function getAttach(key,index){ var dfd = $q.defer(); var image; db.get(key,{attachments:true,binary:false}) .then(function(result){ var name = Object.keys(result._attachments)[index]; var attach = result._attachments[name]; var url = window.URL || window.webkitURL; image = "data:"+attach.content_type+";base64,"+attach.data; dfd.resolve(image); },function(error){ console.log('Error cargando blob:'+error); }); return dfd.promise; } where key is the id of the document and index is the index of the attachment that you want to retrieve. Then you can use it like this:

getAttach(id,0).then(function(result){ image = result; })

Binary:true doesnt work with crypto activated.