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([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中的元素。


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM