req.file 和 req.body 在使用 multer 2.0 时不起作用

问题描述 投票:0回答:1

multer.js

const multer = require("multer");
const upload = multer().single("avatar");
module. Exports = { upload };

用户路由.js

const { upload } = require("../middleware/multer");
 router.route("/register").post(upload, registerUser);

用于注册用户的控制器

const catchAsyncError = require("../../middleware/catchAsyncError");const ErrorHandler = require("../../utils/errorhandler");const cloudinary = require("cloudinary").v2;
// Register a userexports.registerUser = catchAsyncError(async (req, res, next) => {console.log(req.body);console.log(req.file);});
javascript multer cloudinary
1个回答
0
投票

尝试修改模块。导出module.exports并且 const upload = multer().single("avatar"); 可以改为 const upload = multer.single("avatar"); 希望这有效

© www.soinside.com 2019 - 2024. All rights reserved.