How to add attachments?

Hi folks, I might just be missing…how do you add an attachment to a document. It’s not a problem on the mobile with Xamarin and lite, but I can’t find support in the .Net 2.0 SDK. Many thanks for a pointer in the right direction!

With Couchbase Server buckets directly, you have always been able to store binaries as key-values. I think @jmorris can probably give you a pointer to how to handle this in the 2.0 SDK.

Owing to some different plans, Couchbase Mobile changed this and supports attachments to documents. It’s not supported to connect to the Sync Gateway bucket directly. At the moment, the REST API is the only way to access this from Sync Gateway.

Thanks - That makes a lot of sense…I’m afraid I’m still stuggling a bit, however, I’ve tried the Rest API with every combination I can think of…here’s the curl message and response:

teds-mbp:graphics Ted$ curl -vX PUT http://ec2-54-241-255-224.us-west-1.compute.amazonaws.com:4984/sync_srucc/9ef40c1d-dfac-4e41-a987-a23ckk25bc3198?=/tablet.png --data-binary @tablet.png -H “Content-Type: image/png”

PUT /sync_srucc/9ef40c1d-dfac-4e41-a987-a23ckk25bc3198?=/tablet.png HTTP/1.1
User-Agent: curl/7.37.1
Host: ec2-54-241-255-224.us-west-1.compute.amazonaws.com:4984
Accept: /
Content-Type: image/png
Content-Length: 29527
Expect: 100-continue

< HTTP/1.1 415 Unsupported Media Type
< Content-Type: application/json

  • Server Couchbase Sync Gateway/1.00 is not blacklisted
    < Server: Couchbase Sync Gateway/1.00
    < Date: Tue, 10 Feb 2015 17:59:29 GMT
    < Content-Length: 76
  • HTTP error before end of send, stop sending
    <
  • Closing connection 0
    {“error”:“Unsupported Media Type”,“reason”:“Invalid content type image/png”}
    teds-mbp:graphics Ted$

So I’m not sure if there’s a error above, I have a config setting wrong, or what…

Thx again
T

@teddavault

That’s an error for sure, it looks like Couchbase lite attachments do not support image/png. Maybe @traun knows?

-Jeff

It may not be an error, as the request doesn’t match the API docs. Note above I forked discussion off to the Sync Gateway category.

Has anyone figured out how to add an image attachment via the rest api?