Answer the question
In order to leave comments, you need to log in
Why is req.body not defined?
The site has the following code that sends a file to the server:
const uploadFile = target.files[0];
console.log(uploadFile)
const formData = new FormData()
formData.append('upload', uploadFile)
console.log(formData)
const response = await fetch('upload', {
method: 'POST',
body: formData
})
app.post('/upload', upload.single('upload'), (req, res) => {
res.setHeader("Access-Control-Allow-Origin", "*")
res.send(JSON.stringify({id: req.fileUploadId, name: req.fileUploadName }))
})
const uploadFile = target.files;
console.log(req.body.upload[0].name)
console.log(req.body.upload)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question