2014-03-29 27 views
1

我想使用强大的解析表单与多个文件上传,但不知何故结果只显示一个文件。下面是解析的代码,我直接复制从这里举例: 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个文件上传。这个中间件已经过很好的测试,我想我一定在某个地方犯了错误。

我做错了什么?谢谢!

回答

0

我切换到node-multiparty,一个窗体解析器与强大的对象。上传的文件数量正确。 所以也许这是一个强大的bug。使用节点多方可以节省您一些时间。

enter image description here

2

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] ] } } 
+0

我明白了。那就是问题所在。 NPM多久更新一次资料库? –

+0

“强大”的维护者决定何时发布该模块的新版本。 – bnuhero

0

由于截稿时,强大的库已经发生了变化。现在,您必须明确设置IncomingForm对象,最显着的一些参数:

  • 倍数:真

如果你想绕过文件大小:

  • maxFileSize为:(约字节(不是maxFieldsSize))

这使您可以正确使用最新版本的强大