How get blob's url?


#1

Hi! We have the document like this:

{
  "_attachments": {
    "blob_/data/imageData1": {
      "content_type": "image/jpeg",
      "digest": "sha1-z8ukBZJW4t+0kTxynJREE8nxv4I=",
      "length": 1949173,
      "revpos": 1,
      "stub": true
    },
    "blob_/data/imageData2": {
      "content_type": "image/jpeg",
      "digest": "sha1-BOTDSmBjVXokFZqXEYqu5+0rXmA=",
      "length": 331649,
      "revpos": 1,
      "stub": true
    }
  },
  "data": {
    "city": "Tommouth",
    "imageData1": {
      "@type": "blob",
      "content_type": "image/jpeg",
      "digest": "sha1-z8ukBZJW4t+0kTxynJREE8nxv4I=",
      "length": 1949173
    },
    "imageData2": {
      "@type": "blob",
      "content_type": "image/jpeg",
      "digest": "sha1-cddUGmpZKcv/88CFs8WSWiChl6E=",
      "length": 4256580
    },
    "name": "Keegan Terry",
    "phoneNumber": "1-310-141-6382 x22513",
    "postalCode": "67778",
    "state": "Rhode Island",
    "street": "484 Jaren Hollow"
  },
  "date": "2018-09-13T12:44:59.292Z",
  "owner": "andreyMobile",
  "type": "customer"
}

How can I get blob’s url?
In previous version’s of server and sync_gateway we can upload blob’s content from:
http://serverURL:4984/db-name/document-id/blob_1


#2

Which version of Sync Gateway are you talking about?

Running SG 2.0, I have a doc that looks like

{
  "_attachments": {
    "blob_1": {
      "content_type": "image/png",
      "digest": "sha1-4ee4vVIuZwBMObJT0B7hZt5df1Y=",
      "length": 246459,
      "revpos": 1,
      "stub": true
    }
  },
  "cover": {
    "@type": "blob",
    "content_type": "image/png",
    "digest": "sha1-4ee4vVIuZwBMObJT0B7hZt5df1Y=",
    "length": 246459
  },
  "isbn": "todo",
  "title": "Photos from Another Land and Another Time",
  "type": "book"
}

I can get the blob data with

curl -X GET -H "Content-Type: image/png" -H "accept: application/json" "http://localhost:4985/inventory/04e22302-2823-4960-81cd-4d495d323b6c/blob_1"


#3

Couchbase Sync Gateway version": 2.1


#4

So you said in a previous version it worked. Do you mean in 2.0, or before that?


#5

Yes, in version 2.0 I can get blob’s url like your curl.
But now something was changed in couchdatabase and attachment path changed from
“_attachments”: {
“blob_1”: {
}
}

to

attachments": {
"blob
/yourKey”: {
}
}

and I can’t get url. I checked many combinations.


#6

In your example, the URL should be like http://serverURL:4984/db-name/document-id/blob_/data/imageData1 – it’s the document URL plus a slash plus the key from the _attachments dictionary.


#7

I’m entering the URL like this:
http://serverURL:4984/db-name/document-id/blob_/data/imageData1
http://serverURL:4984/db-name/document-id/blob/data/imageData1
http://serverURL:4984/db-name/document-id/_attachments/blob_/data/imageData1
http://serverURL:4984/db-name/document-id/attachments/blob_/data/imageData1

but response:
{"error":"not_found","reason":"unknown URL"}

What’s my mistake?


#8

Huh. Sync Gateway might not be handling the slashes in the attachment name correctly. In those URLs try escaping the slashes, i.e. blob_/data/imageData1 to blob_%2Fdata%2FimageData1.


#9

I reproduced the problem. @jens’ suggestion worked for me. I submitted an issue for it on GitHub, #3751.


#10

@jens @hod.greeley
Thanks! It works.