Answer the question
In order to leave comments, you need to log in
Why is req.files undefined?
I'm trying to get an image and put it in static, but for some reason, when I use form-data in postman, it does not see either req.body or req.files, although I exactly repeated the guide.
The code:
const express = require('express')
const fileUpload = require('express-fileupload');
const fileSevice = require('./fileSevice')
const app = express()
app.use(fileUpload())
app.use(express.json())
app.use(express.static('static'))
app.get('/', (req, res) => {
console.log(req.body)
const file = fileSevice.saveFile(req.files.picture)
res.send(file)
})
app.listen(3000, () => console.log('SERVER STARTED ON PORT ' + 3000))
Answer the question
In order to leave comments, you need to log in
firstly, you need to send not via form-data, but via x-www-form-urlencoded
secondly, you need to add the urlencoded middleware:
app.use(express.urlencoded({ extended: false });
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question