From 5454022f609f88bf67a85d02c39c95c1f3c49a62 Mon Sep 17 00:00:00 2001 From: Jan Lehnardt Date: Tue, 3 Nov 2009 14:22:19 +0000 Subject: 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. git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@832427 13f79535-47bb-0310-9956-ffa450edef68 --- src/couchdb/couch_httpd_db.erl | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'src/couchdb') diff --git a/src/couchdb/couch_httpd_db.erl b/src/couchdb/couch_httpd_db.erl index 4fea824b..3945498d 100644 --- a/src/couchdb/couch_httpd_db.erl +++ b/src/couchdb/couch_httpd_db.erl @@ -708,9 +708,14 @@ db_doc_req(#httpd{method='POST'}=Req, Db, DocId) -> 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), -- cgit v1.2.3