How do I attach and get images from Couchbase DB . I am using a sync
gateway to sync the data from the Couchbase DB to the Couchbase Lite.
I need to do it from the javascript prespective. I know that the images
will get stored as base64 format. But the main issue I am facing is I am
not being
able to convert the binary data back to viewable image .
Below is the code snippet I have for getting the attachments(images)
config.db.get(id,{attachments:true},function(err, doc){
var imgContent = "";
if(err){
alert(JSON.stringify(err)) ;
}else{
var name = doc.imgName
var fields = Object.keys(doc), o, attachments;
if(doc){
fields.map( function (f) {
if (f == '_attachments') {
attachments = doc[f];
for (o in attachments) {
imgContent= "<img
style='width:100%;height:100%;'
src=data:"+attachments[o].content_type+";base64,"+attachments[o].data+">";
}
}
});
}
}
$("#locations").html(imgContent);
});
Regards
Abhishek
--
You received this message because you are subscribed to the Google Groups
"Couchbase Mobile" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/mobile-couchbase/5e5ffcbc-9ffa-4da1-a3fb-8d4a1084158f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.