Uploading a file and passing a additional parameter with multer

妖精的绣舞 提交于 2019-11-30 14:34:40

The problem is that multer that saves files first, and only then writes to req the remaining part of the form - such as hidden fields.

Try this:

app.post(APIpath + "file",function(req,res){
    var storage = multer.diskStorage({
        destination: tmpUploadsPath
    });
    var upload = multer({ storage : storage}).any();

    upload(req,res,function(err) {
        if(err) {
            console.log(err);
            return res.end("Error uploading file.");
        } else {
           console.log(req.body);
           req.files.forEach( function(f) {
             console.log(f);
             // and move file to final destination...
           });
           res.end("File has been uploaded");
        }
    });
});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!