How to delete attachment through syncgateway rest api?

Hi All,
Here is the case we will have more than one attahment ( attachment names are different ) with each document, we are able to load multiple attachments for each document and retrieve them, but we are not able to delete specific attachment ( one among multiple attachments ) of document. Can you please let us know do we have any way to achieve this, your help would be highly appreciated, thanks for your time.

I have gone through below link, it talks about post and get ( with specific attachment name ) and not about delete ( we are looking for DELETE /{db}/{doc}/{attachment} )

http://developer.couchbase.com/documentation/mobile/1.2/develop/references/sync-gateway/rest-api/document-public/index.html

FYI

may be you can update the document’s attachment_list directly to delete specific attachment

Thanks atom_yang for your reply.
looks, as per the available thread, the issue was not solved, so I requested thread for update.
Here is more info with my issue:
DELETE http://xxxxxx:xxxx/attachments/101/sample.pdf?rev=22-6dfd29e7f2d0d9479958b4f441d6df8f
returns 405 method not allowed, can you please suggest me , your help would be highly appreciated and thanks for your time.

When you add a attachment to a doc, as you issue:
your doc: 101 has a attachment sample.pdf.
so when you check you 101 doc, you can get the following property:

  "attachment_list": [
    "sample.pdf"
  ],

then you can update 101 doc that remove attachment_list property or remove attachment from attachment_list.
then you can not access the attachment.
also I am not sure that the attachment is removed.
you can try.

Thanks for your reply atom.

Has the api changed? I don’t have anything called attachment_list. My documents have a map called _attachments:

{
  "owner": "610b116a-0f53-4493-a9a6-548f2ae0981a",
  "_attachments": {
    "low-res": {
      "digest": "sha1-cerZc0TwdY+jPYThuy6Uzbf4O6I=",
      "length": 73292,
      "stub": true,
      "content_type": "image/jpeg",
      "revpos": 63
    },
    "thumbnail": {
      "digest": "sha1-vZg1VSdmZWwe47j2M5TgxhIE/dM=",
      "length": 15983,
      "stub": true,
      "content_type": "image/jpeg",
      "revpos": 182
    }
  } ...,

To remove an attachment from a document do I just remove it from this map?

yes, remove the attachment from _attachments

Thanks. Could you add this to the docs?

Does the underlying attachment binary data get deleted if its no longer referenced?

sorry, I can’t, I am Couchbase user too.

@nick-couchbase

Currently orphan binary attachments do not get compacted away, there is an issue for tracking this and is currently planned for a 1.4 release.

1 Like

Thanks Andy - just curious.

Has there been any update on this?

I don’t think still there is fix available. but you can follow below until fix available from couchbase guys

  1. Instead of deleting doc which has attachment, update the doc with attachment name(digest Id) with _deleted=true which is same as DELETE
  2. Write a view to get these attachment names with(_sync:att:) and delete attachment with REST API provided
1 Like

Where do you get this information from? I am interested in the oridinal thread if possible. Since we are eagerly want to delete docs with attachments. Thanks!