You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ja...@apache.org on 2009/11/03 15:22:19 UTC

svn commit: r832427 - /couchdb/trunk/src/couchdb/couch_httpd_db.erl

Author: jan
Date: Tue Nov  3 14:22:19 2009
New Revision: 832427

URL: http://svn.apache.org/viewvc?rev=832427&view=rev
Log:
Allow updating a doc along with an attachment when posted from an
HTML form.

Patch by Robert Newson.
Closes COUCHDB-436.

We still need tests for the entire form-upload function.

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=832427&r1=832426&r2=832427&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/couch_httpd_db.erl (original)
+++ couchdb/trunk/src/couchdb/couch_httpd_db.erl Tue Nov  3 14:22:19 2009
@@ -708,9 +708,14 @@
         throw({bad_ctype, <<"Invalid Content-Type header for form upload">>})
     end,
     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], []),
-
+    case proplists:is_defined("_doc", Form) of
+    true ->
+        Json = ?JSON_DECODE(proplists:get_value("_doc", Form)),
+        Doc = couch_doc_from_req(Req, DocId, Json);
+    false ->
+        Rev = couch_doc:parse_rev(list_to_binary(proplists:get_value("_rev", Form))),
+        {ok, [{ok, Doc}]} = couch_db:open_doc_revs(Db, DocId, [Rev], [])
+    end,
     UpdatedAtts = [
         #att{name=validate_attachment_name(Name),
             type=list_to_binary(ContentType),