yuanqiao 发表于 2017-2-24 11:02:57

nodejs使用formidable上传多个文件

  首先,在html页面中,表单上传文件的控件需要加上multiple选项,或者multiple="multiple".
  然后,在nodejs程序中处理post数据的路路由中使用formidable格式化表单



var form = new formidable.IncomingForm();
form.uploadDir = configs.productPath;
form.keepExtensions = true;
var files = [];
form.on('file', function (filed, file) {
files.push();
});//whenever a file is received, this will add the file info to the array

form.parse(req, function (err, fields) {
assert.equal(err, null);
//traverse the files here
      }
});
  通过form.on语句将所有上传的文件加入到files里。
  然后,使用array.foreach遍历files中的元素。
页: [1]
查看完整版本: nodejs使用formidable上传多个文件