-3
Guys I have the following request on frontend
formData.append("file", this.file);
formData.append("name", "test");
axios
.post(`${baseApiUrl}/exame`, formData)
In the backend I can recover the value of the "file" field with this function:
const upload = multer({ dest: 'uploads/' }).single("file")
function save(req, res) {
upload(req, res, function (err) {
console.log(req.file) // Acesso ao conteúdo de file
console.log(req.name) // Undefined :(
})
}
However my question is, how do I recover the field "name" and other in case I decide to add?
NOTE: I am calling the upload function this way because I need to capture the errors (if they exist) when recording the file, according to the documentation doc multer
Hello Uilherme, thanks for helping! In case I used this way because I need to capture the errors when saving the file (if any), as shown link. About the req.body it always comes as Undefined :/
– Retiorts
@Rectiorts this was not informed in the question, it seemed more a typo, this you should always explain. I will edit
– Guilherme Nascimento
Really, I forgot to mention it. Thanks, I’m on hold :D
– Retiorts