How do you access Attachments on Couchbase Server or Sync Gateway using SDK?

Is there a way to access attachments via the .Net Couchbase Server API without having to use the Sync Gateway Admin REST API?

Shared bucket access is available in the latest versions of Couchbase and Couchbase Mobile however Attachments are not a construct of Couchbase from what I’ve gathered. So accessing attachment funcitonality/data cannot be accessed with shared bucket access via the .Net SDK.
The only reference I could find was this forum: Storing attachments directly on Couchbase Server where ldoguin specifically mentions one still needs to go through the Sync Gateway to interact with Attachments.

Example:
Server backend with a document in Couchbase. I want to add or modify an attachment to the document. I’m using the .Net SDK -> Can’t except with Sync Gateway Rest API.
Server backend, with a document in Couchbase that has attachments. I want to get the attachment -> Also can’t except with Sync Gateway Rest API.

It is totally possible that I have missed something and there is a way (I’m new to Couchbase), but to date I haven’t found any other way except adding a Couchbase Lite client on the server itself, which is not ideal.

You are right. Read/write of attachments have to go through SGW even with shared bucket access enabled.

Thanks. I’ve been trying to figure out how to delete attachments, could anyone point me in the right direction for this?

You can use Update Document API to update the contents of the Document by removing the _attachments property.

But note that the deleted attachment would remain in the CB server bucket. You can follow the recommendations provided in the Github Ticket to handle the same.

1 Like