diff options
| author | Christopher Lenz <cmlenz@apache.org> | 2009-03-19 20:51:28 +0000 | 
|---|---|---|
| committer | Christopher Lenz <cmlenz@apache.org> | 2009-03-19 20:51:28 +0000 | 
| commit | f73b12a67d852b2ff710acf4510eff5abc472b10 (patch) | |
| tree | ef30a1355d29b62818ae642903377b59b75f4717 | |
| parent | 292091ece9a97c51f92e2dda547e732848db1515 (diff) | |
Bring back Futon attachment uploading that was removed in the recent rep_security merge. Should close COUCHDB-295. Ideally this would have a test, but that will need some trickery.
git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@756186 13f79535-47bb-0310-9956-ffa450edef68
| -rw-r--r-- | src/couchdb/couch_httpd_db.erl | 22 | 
1 files changed, 22 insertions, 0 deletions
| diff --git a/src/couchdb/couch_httpd_db.erl b/src/couchdb/couch_httpd_db.erl index aa491f8c..03fbb001 100644 --- a/src/couchdb/couch_httpd_db.erl +++ b/src/couchdb/couch_httpd_db.erl @@ -471,6 +471,28 @@ db_doc_req(#httpd{method='GET'}=Req, Db, DocId) ->          end_json_response(Resp)      end; +db_doc_req(#httpd{method='POST'}=Req, Db, DocId) -> +    Form = couch_httpd:parse_form(Req), +    Rev = couch_doc:parse_rev(list_to_binary(proplists:get_value("_rev", Form))), +    {ok, [{ok, Doc}]} = couch_db:open_doc_revs(Db, DocId, [Rev], []), + +    NewAttachments = [ +        {validate_attachment_name(Name), {list_to_binary(ContentType), Content}} || +        {Name, {ContentType, _}, Content} <- +        proplists:get_all_values("_attachments", Form) +    ], +    #doc{attachments=Attachments} = Doc, +    NewDoc = Doc#doc{ +        attachments = Attachments ++ NewAttachments +    }, +    {ok, NewRev} = couch_db:update_doc(Db, NewDoc, []), + +    send_json(Req, 201, [{"Etag", "\"" ++ ?b2l(couch_doc:rev_to_str(NewRev)) ++ "\""}], {[ +        {ok, true}, +        {id, DocId}, +        {rev, couch_doc:rev_to_str(NewRev)} +    ]}); +  db_doc_req(#httpd{method='PUT'}=Req, Db, DocId) ->      update_doc(Req, Db, DocId, couch_httpd:json_body(Req)); | 
