PUT /{db}/{doc}/{attachment}

In this document

This request adds or updates the supplied request content as an attachment to the specified document. The attachment name must be a URL-encoded string (the file name). You must also supply either the rev query parameter or the If-Match HTTP header for validation, and the Content-Type headers (to set the attachment content type).

When uploading an attachment using an existing attachment name, the corresponding stored content of the database will be updated. Because you must supply the revision information to add an attachment to the document, this serves as validation to update the existing attachment.

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

Request


Request headers

Query parameters

NameTypeDescriptionDefault
rev stringRevision identifiernone

Message body

The message body contains the attachment, in the format specified in the Content-Type header.

Response


Status codes

Response headers

Message body

The response is a JSON document that contains the following objects:

NameTypeDescription
id StringDocument identifier
ok BooleanIndicates whether the operation was successful
rev Stringrevision identifier

Example


The following example adds a plain text attachment to the document identified by LemonChicken in the cookbook database.

Request

PUT /cookbook/LemonChicken/lcnote.txt?rev=1-78abf9a6508671ba8338e4ef6daa910a HTTP/1.1
Host: localhost:59840
Content-Type: text/plain
Some notes about the Lemon Chicken recipe from testers
* This recipe is fabulous
* I wish it made more servings

Response

HTTP/1.1 201 Created
Accept-Ranges: bytes
Content-Length: 91
Content-Type: application/json
Date: Fri, 13 Dec 2013 22:52:49 GMT
Etag: "2-6847bbc089e24db84bd0371b9c169566"
Location: http://localhost:59840/cookbook/LemonChicken/lcnote.txt
Server: CouchbaseLite 1.486
{
  "id" : "LemonChicken",
  "rev" : "2-6847bbc089e24db84bd0371b9c169566",
  "ok" : true
}