Reputation: 409
I am trying to send an image file to my backend express.js api from my react frontend. But in my console.log i just get an empty object that looks like {} on the backend side. What is wrong with react.js api call that wont let me see the file in the console.log on the backend.
//Backend API
app.post('/api/v1/media', function (req, res) {
console.log(req.body);
res.json('api called');
});
//React JS api call
const files = e.target.files;
console.log(files);
setLoading(true);
const res = await fetch(
'http://localhost:4000/api/v1/media',
{
method:"POST",
headers: {'Content-Type':'application/json'},
body: JSON.stringify(files[0])
}`enter code here`
)
const file = await res.json();
Upvotes: 0
Views: 68