couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cml...@apache.org
Subject svn commit: r756186 - /couchdb/trunk/src/couchdb/couch_httpd_db.erl
Date Thu, 19 Mar 2009 20:51:28 GMT
Author: cmlenz
Date: Thu Mar 19 20:51:28 2009
New Revision: 756186

URL: http://svn.apache.org/viewvc?rev=756186&view=rev
Log:
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.

Modified:
    couchdb/trunk/src/couchdb/couch_httpd_db.erl

Modified: couchdb/trunk/src/couchdb/couch_httpd_db.erl
URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_httpd_db.erl?rev=756186&r1=756185&r2=756186&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/couch_httpd_db.erl (original)
+++ couchdb/trunk/src/couchdb/couch_httpd_db.erl Thu Mar 19 20:51:28 2009
@@ -471,6 +471,28 @@
         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));
 



Mime
View raw message