我试图使用formidable来解析一个有多个文件上传的表单,但不知何故结果只显示了一个文件。下面是我直接从示例中复制的解析代码:https://github.com/felixge/node-formidable
var form = new formidable.IncomingForm();
form.multiples = true; // per their documents
form.parse(req, function(err, fields, files) {
res.writeHead(200, {'content-type': 'text/plain'});
res.write('received upload:\n\n');
res.end(util.inspect({fields: fields, files: files})); // files only contain one file,
// and files.length is undefined. It is not an array.
});这是我的HTML:
<FORM action="/file"
enctype="multipart/form-data"
method="post">
<br>
What is your name?
<INPUT type="text" name="kk1_submit-name"><BR>
What files are you sending?
<INPUT type="file" multiple="multiple" name="uploads"><BR>
<INPUT type="submit" value="Upload">
</FORM>输出的json对象只有一个文件对象,files.length没有定义,即使我选择了5个文件进行上传。这个中间件测试得很好,我想我一定是弄错了。
我做错什么了?谢谢!
发布于 2014-03-29 20:35:43
formidable模块一个月前开始支持多文件上传。但npmjs.org中的formidable模块在11个月前就更新了。因此,您需要手动安装最新的formidable。
git clone git://github.com/felixge/node-formidable.git node_modules/formidable现在再次运行应用程序,您应该会得到正确的输出:
received upload:
{ fields: { title: '' },
files: { upload: [ [Object], [Object] ] } }发布于 2017-11-19 07:02:55
从写到现在,这个强大的库已经发生了变化。现在必须显式设置IncomingForm对象的一些参数,最值得注意的是:
如果您想绕过文件大小:
以字节为单位的
这使您能够正确使用最新版本的formidable
发布于 2014-03-29 19:27:42
我换成了node-multiparty,这是一个从formidable升级而来的表单解析器。上传的文件数量正确。因此,这可能是一个可怕的错误。使用node-多方可以节省你的时间。

https://stackoverflow.com/questions/22730263
复制相似问题