我试图将表单数据发布到我的 express js 服务器端。这是我的pug文件
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")
Run Code Online (Sandbox Code Playgroud)
之后,我尝试使用req.body内部服务器端 js记录发布数据,如下所示。那是我的profile.js
router.post('/', function (req, res) {
console.log('Body- ' + JSON.stringify(req.body));
});
Run Code Online (Sandbox Code Playgroud)
这是我的控制台结果
body- {}
如果我发布没有enctype="multipart/form-data"like form(action="/profile" method="post"),我可以从我的控制台结果中获取发布数据。