couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Apache Wiki <wikidi...@apache.org>
Subject [Couchdb Wiki] Update of "HttpDocumentApi" by JanLehnardt
Date Thu, 17 Jul 2008 00:02:22 GMT
Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Couchdb Wiki" for change notification.

The following page has been changed by JanLehnardt:
http://wiki.apache.org/couchdb/HttpDocumentApi

------------------------------------------------------------------------------
  
  == Attachments ==
  
+ Documents can have attachments just like email. There are two ways to use attachments. The
first one is inline with your document and it described first. The second one is a separate
REST API for attachments that is described a little further down.
+ 
+ === Inline Attachments ===
- Documents can have attachments just like email. On creation, attachments go into a special
''_attachments'' attribute of the document. They are encoded in a JSON structure that holds
the name, the content_type and the base64 encoded data of an attachment. A document can have
any number of attachments.
+ On creation, attachments go into a special ''_attachments'' attribute of the document. They
are encoded in a JSON structure that holds the name, the content_type and the base64 encoded
data of an attachment. A document can have any number of attachments.
  
  When retrieving documents, the attachment's actual data is not included, only the metadata.
The actual data has to be fetched separately, using a special URI.
  
@@ -502, +505 @@

  }
  }}}
  
+ 
+ === Standalone Attachments ===
+ CouchDB allows to create, change and delete attachments without touching the actual document.
As a bonus feature, you do not have to base64 encode your data. This can significantly speed
up requests since CouchDB and your client do not have to do the base64 conversion.
+ 
+ You need to specify a MIME type using the Content-Type header. CouchDB will serve the attachment
with the specified Content-Type when asked.
+ 
+ To create an attachment:
+ {{{
+ PUT somedatabase/document/attachment?rev=123 HTTP/1.0
+ Content-Length: 245
+ Content-Type: image/jpeg
+ 
+ <JPEG data>
+ }}}
+ 
+ CouchDB replies:
+ {{{
+ {"ok": true, "id": "document", "rev": "765B7D1C"}
+ }}}
+ 
+ Note that you can do this on a non-existing document. The document and attachment will be
created implicitly for you. A revision id must not me specified in this case.
+ 
+ To change an attachment:
+ {{{
+ PUT somedatabase/document/attachment?rev=765B7D1C HTTP/1.0
+ Content-Length: 245
+ Content-Type: image/jpeg
+ 
+ <JPEG data>
+ }}}
+ 
+ CouchDB replies:
+ {{{
+ {"ok": true, "id": "document", "rev": "766FC88G"}
+ }}}
+ 
+ To delete a document:
+ 
+ {{{
+ DELETE somedatabase/document/attachment?rev=765B7D1C HTTP/1.0
+ }}}
+ 
+ CouchDB replies:
+ {{{
+ {"ok":true,"id":"document","rev":"519558700"}
+ }}}
+ 
+ To retrieve an attachment:
+ 
+ {{{
+ GET somedatabase/document/attachment HTTP/1.0
+ }}}
+ 
+ CouchDB replies
+ {{{
+ Content-Type:image/jpg
+ 
+ <JPEG data>
+ }}}
+ 
+ 
  == ETags/Caching ==
  
  CouchDB sends an ''ETag'' Header for document requests. The ETag Header is simply the document's
revision.

Mime
View raw message