Couchbase - getting image attachment

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”: [
“parents”: [
“bodies”: [
“channels”: [
“channels”: {
“public”: null
“time_saved”: “2014-11-07T12:10:11.5801239+05:30”
“channels”: [
“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 = “”;
alert(JSON.stringify(err)) ;

var name = doc.imageName
var attachments = doc._attachments;
for (o in attachments) {
imgContent = “”;

I do not see the binary data getting converted to a view able image.


Hey @shettyabhishek829,

The SHA1 is a secure hash algorithm and going that route to display the image from the attachment might be slightly difficult.

Instead, you may have an image tag pointed to the correct URL of interest

   <img src="URL">

The URL is: “document URL” / “attachment name”