summaryrefslogtreecommitdiff
path: root/src/couchdb
diff options
context:
space:
mode:
authorChristopher Lenz <cmlenz@apache.org>2008-08-30 21:09:31 +0000
committerChristopher Lenz <cmlenz@apache.org>2008-08-30 21:09:31 +0000
commit796a66de5f10b219c5ed196a8c97ed4bd3a227a2 (patch)
treec7283a48b96f9f28b4a815ca47ebbee7064e0732 /src/couchdb
parentc5a79c36f230b69e5ad810474316a52474bc4ad9 (diff)
Implement attachment uploading in Futon.
git-svn-id: https://svn.apache.org/repos/asf/incubator/couchdb/trunk@690590 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/couchdb')
-rw-r--r--src/couchdb/couch_httpd.erl26
1 files changed, 25 insertions, 1 deletions
diff --git a/src/couchdb/couch_httpd.erl b/src/couchdb/couch_httpd.erl
index 1e5551e6..22adb7dd 100644
--- a/src/couchdb/couch_httpd.erl
+++ b/src/couchdb/couch_httpd.erl
@@ -609,6 +609,30 @@ handle_doc_request(Req, 'GET', _DbName, Db, DocId) ->
end_json_response(Resp)
end;
+handle_doc_request(Req, 'POST', _DbName, Db, DocId) ->
+ Form = mochiweb_multipart:parse_form(Req),
+ Rev = proplists:get_value("_rev", Form),
+ NewAttachments = [{Name, {ContentType, Content}} ||
+ {Name, {ContentType, _}, Content} <-
+ proplists:get_all_values("_attachments", Form)],
+
+ Doc = case couch_db:open_doc_revs(Db, DocId, [Rev], []) of
+ {ok, [{ok, Doc0}]} -> Doc0#doc{revs=[Rev]};
+ {ok, [Error]} -> throw(Error)
+ end,
+
+ #doc{attachments=Attachments} = Doc,
+ NewDoc = Doc#doc{
+ attachments = Attachments ++ NewAttachments
+ },
+ {ok, NewRev} = couch_db:update_doc(Db, NewDoc, []),
+
+ send_json(Req, 201, [{"Etag", "\"" ++ NewRev ++ "\""}], {obj, [
+ {ok, true},
+ {id, DocId},
+ {rev, NewRev}
+ ]});
+
handle_doc_request(Req, 'PUT', _DbName, Db, DocId) ->
Json = {obj, DocProps} = cjson:decode(Req:recv_body(?MAX_DOC_SIZE)),
DocRev = proplists:get_value("_rev", DocProps),
@@ -694,7 +718,7 @@ handle_doc_request(Req, 'MOVE', _DbName, Db, SourceDocId) ->
]});
handle_doc_request(_Req, _Method, _DbName, _Db, _DocId) ->
- throw({method_not_allowed, "DELETE,GET,HEAD,PUT,COPY,MOVE"}).
+ throw({method_not_allowed, "DELETE,GET,HEAD,POST,PUT,COPY,MOVE"}).
% Useful for debugging
% couch_doc_open(Db, DocId) ->