diff options
author | Jan Lehnardt <jan@apache.org> | 2009-11-03 14:22:19 +0000 |
---|---|---|
committer | Jan Lehnardt <jan@apache.org> | 2009-11-03 14:22:19 +0000 |
commit | 5454022f609f88bf67a85d02c39c95c1f3c49a62 (patch) | |
tree | 6c15e6cafc41dd76b68d184129ec7a798f920bd0 /src/couchdb | |
parent | 9bd34f364e1d9d3a02391cc3ace1ee98d84ae547 (diff) |
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
Diffstat (limited to 'src/couchdb')
-rw-r--r-- | src/couchdb/couch_httpd_db.erl | 11 |
1 files changed, 8 insertions, 3 deletions
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), |