CouchDB,Kanso,文件上载错误
我试图在创建CouchDB文档时将其附加到CouchDB文档 这是HTML代码:CouchDB,Kanso,文件上载错误,couchdb,couchapp,kanso,Couchdb,Couchapp,Kanso,我试图在创建CouchDB文档时将其附加到CouchDB文档 这是HTML代码: <form> <input type="hidden" name="type" value="devtest"/> <input type="file" name="_attachments" id="picture" accept="image/*" multiple/> <button type="submit">Go</button> &
<form>
<input type="hidden" name="type" value="devtest"/>
<input type="file" name="_attachments" id="picture" accept="image/*" multiple/>
<button type="submit">Go</button>
</form>
这将产生以下错误消息:
{"error":"doc_validation","reason":"Bad special document member: _attachments"}
我正在使用CouchDB 1.3.1和kanso 0.2.2以及db 0.1.0。好吧,我想我已经找到了答案。我的两个假设被证明是根本错误的。首先,不能仅使用名为
\u attachments
的输入字段上载附件。其次,CouchDB似乎不接受文件,除非应该附加文件的文档已经存在。(在这一点上我可能错了,但这对我不起作用。)
以下是适合我的解决方案:
$(document).on('submit', '#userctl form', function(e) {
e.preventDefault()
var data = $(this).serializeObject();
// Use the Kanso API to create a normal document without attachments
m.db.current().saveDoc(
data,
function(err,res) {
// Use ajaxSubmit provided by the jquery.forms plugin to submit the attachments
$('#userctl form').ajaxSubmit({
url: m.db.current().url + '/' + res.id,
data: {
_rev: res.rev // Provide a revision, otherwise the upload fails
},
success: function(res) {
console.log(res);
}
});
}
);
});
此方法需要以下两个插件:
- 好吧,我想我已经明白了。我的两个假设被证明是根本错误的。首先,不能仅使用名为
\u attachments
的输入字段上载附件。其次,CouchDB似乎不接受文件,除非应该附加文件的文档已经存在。(在这一点上我可能错了,但这对我不起作用。)
以下是适合我的解决方案:
$(document).on('submit', '#userctl form', function(e) {
e.preventDefault()
var data = $(this).serializeObject();
// Use the Kanso API to create a normal document without attachments
m.db.current().saveDoc(
data,
function(err,res) {
// Use ajaxSubmit provided by the jquery.forms plugin to submit the attachments
$('#userctl form').ajaxSubmit({
url: m.db.current().url + '/' + res.id,
data: {
_rev: res.rev // Provide a revision, otherwise the upload fails
},
success: function(res) {
console.log(res);
}
});
}
);
});
此方法需要以下两个插件: