• 首先,通过app.use()加载bodyPaser插件
  • 设置上传文件的临时目录
app.use(
    express.bodyParser({
        uploadDir: path.join(__dirname, 'uploadtmp')
    })
);
  • 写接收文件的action
var fs = require('fs');
exports.uploadPic = function(db){
    return function(req, res){
    if (req.files && req.files.upload) {    //‘upload’为提交表单name
        var tmpPath = req.files.upload.path; //获取临时文件路径
        var targetPath = '../filepath';    //转存到目标文件
        fs.rename(tmpPath, targetPath, function(err){
            if (err){
                throw err;
            } else{}
        });
    }
};