【发布时间】:2014-04-11 01:08:02
【问题描述】:
这是我目前所拥有的。这是表格(根据cybersam的回答更新)
<form method="POST" action="/view" enctype="multipart/form-data">
<input type="image" src="/images/094_max.jpg" name="bigImage" width="300"/>
<input type="hidden" name="file_name" value="{ source: 'test_image.jpg',
_id: 53471acd4fe44ddf04a3f752,
__v: 0,
score: 0 }"/>
</form>
这是“/view”路线
app.post('/view', vote_and_view);
这里是路由中引用的vote_and视图函数
function vote_and_view(req,res){
var form = new multiparty.Form();
form.parse(req, function(err,fields){
if(err) console.error(err)
console.log(fields["file_name"][0])});
res.render('viewImage');
}
我正在尝试使用这个:https://github.com/andrewrk/node-multiparty。现在它返回一个类似
的对象{ source: '094_max.jpg',
_id: 53470d4b9a2a82755d911f28,
__v: 0,
score: 0 }
当我尝试调用 object.source 或 object['source'] 时,它返回未定义。然而对象本身被返回了?为什么会发生这种情况?如何获得此来源?
附:当我看到 _id: 53470d4b9a2a82755d911f28 时,它让我认为由于末尾的 f 而导致该整数有问题。除了我不确定如何将它转换为字符串,因为它是由我的模板从 mongodb 生成的。
【问题讨论】:
标签: javascript forms node.js post