enu*_*car 5 javascript node.js express multer
在我的项目中,管理员能够上传 MP3 文件并向其提交参数(例如歌曲名称)。
我决定使用multer 中间件来处理multipart/form-data.
我的问题是req.body.gender返回总是未定义,因为我必须在uploadSong侦听器内使用它。我想在性别为零时上传歌曲。
索引.ejs
<form method="post" action="/acp" role="publish" enctype="multipart/form-data">
<div class="form-group">
<input type="file" name="song" id="song" accept="audio/mpeg">
</div>
<input type="checkbox" name="gender" checked data-toggle="toggle" data-on="Male" data-off="Female">
</form>
Run Code Online (Sandbox Code Playgroud)
应用程序.js
var uploadSong = upload.single('song');
app.post('/acp', isLoggedIn, function (req, res) {
console.log(req.body.gender); // returns "undefined"
if(req.body.gender == 0) { // returns "undefined"
uploadSong(req, res, function (err) {
if (err) {
res.send('uploaded');
return;
}
res.redirect('/');
});
}
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7692 次 |
| 最近记录: |