码迷,mamicode.com
首页 > Web开发 > 详细

nodejs使用formidable上传多个文件

时间:2016-07-20 23:02:12      阅读:211      评论:0      收藏:0      [点我收藏+]

标签:

首先,在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([filed, file]);
    });//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中的元素。

nodejs使用formidable上传多个文件

标签:

原文地址:http://www.cnblogs.com/netaddi/p/5689831.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!