I have pushed a doc with attachment to the Couchbase DB. When i see that using the Couchbase server console, I see the attachment as expected …
{
"_attachments": {
“image1.jpg”: {
“content_type”: “image/jpg”,
“digest”: “sha1-FUmWqdCQLf+GUkI5dywWHPnJpAs=”,
“length”: 1630,
“revpos”: 1,
“stub”: true
}
},
"_sync": {
“rev”: “1-943786f2cee7de12357df69c4ff128e5”,
“sequence”: 295,
“history”: {
“revs”: [
“1-943786f2cee7de12357df69c4ff128e5”
],
“parents”: [
-1
],
“bodies”: [
""
],
“channels”: [
[
“public”
]
]
},
“channels”: {
“public”: null
},
“time_saved”: “2014-11-07T12:10:11.5801239+05:30”
},
“channels”: [
“public”
],
“imageId”: “img1”,
“imgName”: “image1.jpeg”,
“type”: “list”
}
When I retrieve the image i get the binary data
"digest": “sha1-FUmWqdCQLf+GUkI5dywWHPnJpAs=”,
How do i convert it to the proper viewable image format . I need to do this in javascript - below is the code that I am currently using to retrieve image.
var id = “891d9e30eb194e863df67f1bc70530ae”;
config.db.get(id,function(err, doc){
var imgContent = “”;
var imgData = “”;
if(err){
alert(JSON.stringify(err)) ;
}else{
var name = doc.imageName
var attachments = doc._attachments;
for (o in attachments) {
imgContent = “”;
}
}
$("#locations").html(imgContent);
});
I do not see the binary data getting converted to a view able image.
regards
Abhishek