How to delete attachment through syncgateway rest api?


#1

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


#2

FYI

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


#3

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.


#4

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.


Sync Gateway attachments on separate disk
#5

Thanks for your reply atom.


#6

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?


#7

yes, remove the attachment from _attachments


#8

Thanks. Could you add this to the docs?

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


#9

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


#10

@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.


#11

Thanks Andy - just curious.