I am making the following call to update an image via the Sync Gateway (withOUT using the mobile components) and while the return status is OK, the BLOB never gets updated.
TL;DR: The last path component in the URL is probably wrong. To check, do a GET request of the document, and look at the key in the _attachments sub-dictionary. That key string is the path component you should use.
Details: Sync Gateway doesn’t yet support the newer blob schema introduced in Couchbase Lite 2. Instead, it expects attachments to be in an _attachments sub-dictionary. When CBL pushes a doc to SG, it creates this sub-dictionary and creates shadow copies of the blobs in it. (The reverse happens when it pulls from SG.)
So in SG, your blob is going to appear as something like {"_attachments":{"blob1":{"digest":........}}}. The name of the attachment there is blob1, and to PUT to it you should add blob1 as the final path component after the document ID.
We realize this is kind of annoying. There just hasn’t been time to rewrite SG’s attachment handling code to make it work the same way as CBL (especially since SG still supports CBL 1.4, so it’d have to support both schemas.)
Jens, thank you for the explanation. I do think, however, that I am using the correct attachment name. As the GET JSON result shows, my attachment is called blob_/AdImage, which I am using as the final part of my path.
Interestingly, the SG gives me an OK response, but nothing is updated.
You’re right, that PUT request should have worked. And it’s especially weird that it would get a 200 response but nothing happens (I assume you checked by doing a GET of the document or the attachment afterwards?) Any idea, @adamf?
I have the same question @jens just asked - how are you attempting to verify whether it was successful afterward? (GET document? GET attachment?) . I suspect the problem might be on that side, particularly around whether the forward slash in the path is being escaped properly on the GET.
In that case, this is the scenario @jens described above. Attachments created via the REST API in Sync Gateway don’t use the newer blob schema introduced in CBL 2.0, and don’t store the blob metadata within the document directly - it’s stored in the _attachments property.
So is there a way to accomplish what I’m trying to do? I need to add / update an attachment to the server so that it then propagates to all of the clients.
Scenario: I have a central Windows app that talks directly with the server. That app needs to attach an image to a document. That image, in turn, needs to be replicated to all clients.
You can certainly do that. But you’ll need to use the SG REST API to read attachments (data or metadata). I.e. if you send SG a GET request to the document, or the attachment, you should see it’s been updated. And Couchbase Lite will get the updated attachment too.
So issuing this request: GET /ebookh/Directory~1d41e77f-f7e5-e511-80e5-002590701742 give the following response. Does this then tell me that the attachment is there and Couchbase Lite will get it from SG as well?
Is there any to use the server to see / verify the attachment?