Skip to content

Commit

Permalink
Highlighting
Browse files Browse the repository at this point in the history
  • Loading branch information
synhershko committed Apr 25, 2012
1 parent 22c24a4 commit 693e731
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions docs/http-api/http-api-attachments.markdown
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
#HTTP API - Attachment Operations

##PUT <a id="put"></a>
## PUT

Perform a PUT request to /static/{attachment key} to create the specified attachment at the given URL:

[code lang=powershell]
> curl -X PUT http://localhost:8080/static/users/ayende.jpg -d "[.. binary image data ...]"
[/code]

For a successful request, RavenDB will respond with the id it generated and an HTTP 201 Created response code:

[code lang=plain]
HTTP/1.1 201 Created
Location: /static/users/ayende.jpg
[/code]

It is important to note that a PUT in RavenDB will always create the specified attachment at the request URL, if necessary overwriting what was there before.

Expand All @@ -28,26 +32,34 @@ While putting an attachment, it is possible to store metadata about it using HTT

In addition to that, any custom HTTP header will also be stored and sent back to the client on GET requests for the attachment.

##GET <a id="get"></a>
## GET
Raven supports the concept of attachments. Attachments are binary data that are stored in the database and can be retrieved by a key.
Retrieving an attachment is done by performing an HTTP GET on the following URL:

[code lang=powershell]
> curl -X GET http://localhost:8080/static/{attachment key}
[/code]

For example, the following request:

[code lang=powershell]
> curl -X GET http://localhost:8080/static/users/ayende.jpg
[/code]

Will retrieve an attachment whose key is "users/ayende.jpg", the response to the request is the exact byte stream that was stored in a previous [PUT](http://ravendb.net/docs/http-api/attachments/http-api-put-attachments) request.

##DELETE <a id="delete"></a>
## DELETE

Perform a DELETE request to delete the attachment specified by the URL:

[code lang=powershell]
> curl -X DELETE http://localhost:8080/static/users/ayende.jpg
[/code]

For a successful delete, RavenDB will respond with an HTTP response code 204 No Content:

[code lang=plain]
"HTTP/1.1 204 No Content"
[/code]

The only way a delete can fail is if [the etag doesn't match](http://ravendb.net/docs/http-api/http-api-comcurrency), even if the attachment doesn't exist, a delete will still respond with a successful status code.

0 comments on commit 693e731

Please sign in to comment.