I tried to post form data to my express js server side. This is my pug
file
form(action="/profile" method="post" enctype="multipart/form-data")
input(type="file" accept="image/*" name="profileimage")
input(type="text" name="username")
input(type="submit" value="Upload")
After that I tried to log the post data with req.body
inside server side js as follow. That is my profile.js
router.post('/', function (req, res) {
console.log('Body- ' + JSON.stringify(req.body));
});
And this is my console result
body- {}
If I post without enctype="multipart/form-data"
like form(action="/profile" method="post")
, I can get the post data from my console result.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…