PUT /{db}/{doc}/{attachment}
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
-
Content-Type—Required—MIME type of the attachment.-
If-Match– Required if therevquery parameter is not supplied —Revision identifier of the requested document.
-
Query parameters
| Name | Type | Description | Default |
|---|---|---|---|
rev
| string | Revision identifier | none |
Message body
The message body contains the attachment, in the format specified in the Content-Type header.
Response
Status codes
- 200 OK – Attachment successfully removed
- 202 Accepted – Request was accepted, but changes are not yet stored on disk
- 400 Bad Request – Invalid request body or parameters
- 401 Unauthorized – Write privileges required
- 404 Not Found – Specified database, document or attachment was not found
- 409 Conflict – Document’s revision wasn’t specified or it’s not the latest
Response headers
-
Accept-Ranges– Range request aware. Used for attachments with application/octet-stream -
Content-Encoding– Used compression codec. Available if the attachment’s content is a compressible type. -
Content-Length– Attachment size. If compression codec is used, this value represents the compressed size, not the actual size. -
Content-MD5– Base64 encoded MD5 binary digest -
ETag—Revision identifier enclosed in double quotes
Message body
The response is a JSON document that contains the following objects:
| Name | Type | Description |
|---|---|---|
id
| String | Document identifier |
ok
| Boolean | Indicates whether the operation was successful |
rev
| String | revision 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
}