6.8. PUT /db/doc/attachment

6.8.1. Updating an Existing Attachment
MethodPUT /db/doc/attachment
Request Raw document data
Response JSON document status
Admin Privileges Requiredno
Query ArgumentsArgumentrev
 Description Current document revision
 Optionalno
 Typestring
HTTP HeadersHeaderContent-Length
 DescriptionLength (bytes) of the attachment being uploaded
 Optionalno
   
 HeaderContent-Type
 DescriptionMIME type for the uploaded attachment
 Optionalno
   
 HeaderIf-Match
 DescriptionCurrent revision of the document for validation
 Optionalyes
   
Return Codes
201 Attachment has been accepted

Upload the supplied content as an attachment to the specified document (doc). The attachment name provided must be a URL encoded string. You must also supply either the rev query argument or the If-Match HTTP header for validation, and the HTTP headers (to set the attacment content type). The content type is used when the attachment is requested as the corresponding content-type in the returned document header.

For example, you could upload a simple text document using the following request:

PUT http://couchdb:5984/recipes/FishStew/basic?rev=8-a94cb7e50ded1e06f943be5bfbddf8ca
Content-Length: 10
Content-Type: text/plain

Roast it

Or by using the If-Match HTTP header:

PUT http://couchdb:5984/recipes/FishStew/basic
If-Match: 8-a94cb7e50ded1e06f943be5bfbddf8ca
Content-Length: 10
Content-Type: text/plain

Roast it

The returned JSON contains the new document information:

{
   "id" : "FishStew",
   "ok" : true,
   "rev" : "9-247bb19a41bfd9bfdaf5ee6e2e05be74"
}

Note

Uploading an attachment updates the corresponding document revision. Revisions are tracked for the parent document, not individual attachments.