[英]Using enctype="multipart/form-data" ends with csrf error
I am using multer and csurf package.我正在使用 multer 和 csurf 包。
What is problem is that when i add enctype="multipart/form-data"
in form i get invalid csrd token.问题是当我在表单中添加
enctype="multipart/form-data"
,我得到了无效的 csrd 令牌。
app.js应用程序.js
// CSRF BEFORE ROUTES!!!
app.use(bodyParser.urlencoded({
extended: false
}))
app.use(cookieParser())
app.use(csrf());
app.use(function (req, res, next) {
res.locals.csrfToken = req.csrfToken();
next();
});
// Routes
app.use("/", webRoutes);
app.use("/cms", cmsRoutes);
and part of my users route which is inside my cmsRoutes和我的用户路线的一部分,它在我的 cmsRoutes 内
router.post("/edit", isAuthenticated, upload.single('avatar'), profile.user_edit_profile);
I found other people having the same problem.我发现其他人也有同样的问题。 But cant find any solution to this.
但找不到任何解决方案。
Solved.解决了。 Just needed to put MULTER BEFORE CSRF.
只需要将 MULTER 放在 CSRF 之前。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.