在Postman上,如果有一个POST请求,并且在Body >.中添加了。生的 JSON文件,可以在代码内部用 req.params.thatProperty.
例如,我们在Body中有这样的JSON。
{
"email": "[email protected]",
"password": "secret"
}
在代码中。
app.post('/myUrl', (req, res) => {
//here we can access the email by req.params.email
}
我的问题是,如果在Body中有> form-data 就像下面的截图一样,我们怎样才能访问请求的邮件呢?那里没有 req.params
在这种情况下。
但因为我上传的是一个文件,而且我使用的是 Multer我有机会接触到 req.file
. 问题是req.file中只有图片相关信息,没有邮件相关信息。
函数是这样开始的。
app.post('/upload', upload.single('value'), (req, res, next) => {
//how can I have access to the email from the request here?
}
你的表单数据应该在req.body中。