mercredi 21 avril 2021

On post request req.query returns empty dictionary in express node

I want to get post query values to create a new row in the database. But in req.query It don't works. I also tried with body-parser but it also didn't worked. The code

const storage = multer.diskStorage({
    destination: (req, file, cb) => {
        cb(null, './static/image/')
    },
    filename: (req, file, cb) => {
        const { originalname } = file;
        cb(null, originalname)
        filename = originalname;
    }
})
const upload = multer({ storage: storage })

app.post('/admin/song/create', upload.single('file'),  async(req, res) => {
    console.log(req.query)
    res.redirect('/admin')
})

And I also did set the middleware for body-parser but It also don't work. But It does work with GET requests. Why It doesn't work with the POST request. If Anyone knows Please respond. It will be helpful.

Thank You Very Much




Aucun commentaire:

Enregistrer un commentaire