I want to send a file to my express app as backend. My problem is that my body is send as type application/json and I want to send this as a form-data and later upload this file using multer -> https://github.com/expressjs/multer
I don't know how to prepare fetch call to get it later in express.
fetch('/api/data', {
method: 'POST',
headers: {
Accept: 'application/form-data',
'Content-Type': 'application/json',
},
body: JSON.stringify(data),
})
.then((resp) => resp.json())
.then((data) => console.log(data));
When I want to log req.file in api breakpoint I'm getting undefined.
app.post('/api/data', upload.single('cv'), (req, res) => {
console.log(req.body);
console.log(req.file);
res.send({ name: 'Hello world!' });
});
I store react data from form using hooks and this object looks like this:
{
name: 'test',
surname: 'test2',
cv: 'C:\\fakepath\\Babel error.png'
}