简体   繁体   English

使用 enctype="multipart/form-data" 以 csrf 错误结束

[英]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.

相关问题 使用 enctype="multipart/form-data" 时出现 CSRF 错误 - I get CSRF error when using enctype=“multipart/form-data” 带有Post Method和enctype的表单Multipart / form-data不在Nodejs Express multer模块上提交 - Form with Post Method and enctype Multipart/form-data is not being submitted on Nodejs Express multer module 如何通过sails.js中的表单获取数组/对象(使用enctype multipart / form-data) - How to get arrays/objects sent via form in sails.js (with enctype multipart/form-data) 当enctype =“ multipart / form-data”(Node.js)时,无法读取Jade Form字段 - Unable to read a jade form field when it has enctype=“multipart/form-data” (Nodejs) 解析node.js Express应用程序,形式为enctype =“ multipart / form-data”销毁请求主体? - Parse node.js express app, form enctype=“multipart/form-data” destroys request body? 当表单设置为 enctype='multipart/form-data' 时,express-validator 给出未定义的值 - express-validator giving undefined value when form set to enctype='multipart/form-data' 将数据插入MongoDB并使用enctype =“ multipart / form-data”上传图像问题 - Insert data into MongoDB and upload image issue with enctype=“multipart/form-data” 当我输入enctype =“multipart / form-data”和输入[type =“file”]时,使用PassportJS“丢失凭据” - “Missing credentials” with PassportJS when I put enctype=“multipart/form-data” and an input[type=“file”] enctype="multipart/form-data" 总是返回 null 输入,但它是 multer 必须工作的,我们如何解决这个问题? - enctype=“multipart/form-data” always return null input but it is a must for multer to work how can we fix this? 在NodeJS中使用multipart / form-data进行POST - POST using multipart/form-data in NodeJS
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM