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