简体   繁体   中英

Using enctype="multipart/form-data" ends with csrf error

I am using multer and csurf package.
What is problem is that when i add enctype="multipart/form-data" in form i get invalid csrd token.

app.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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM