How can we send data in MySQL when the form has set to enctype=“multipart/form-data” in node.js?

前端 未结 1 1736
孤城傲影
孤城傲影 2020-12-22 11:12

This enctype="multipart/form-data" blocking me from sending my data to mysql but it is a must for multer to work. I\'m trying to store the image f

相关标签:
1条回答
  • 2020-12-22 11:29

    suggestion

    reference this

    your data that inserted into database isn't on req.body object instead some where else. like req.files.file object. you can print out the log by using console.log('req.file' + req.file + 'req.files' + req.files) on your app.js file

    app.post('/save',upload.single('featured_img'), function (req, res) {
    
        console.log('req.file' + req.file + 'req.files' + req.files)
    
        let sql = "INSERT INTO `music`(`featured_img`, `title`, `band_name`, `audio`) VALUES ('" + req.body.featured_img + "', '"+req.body.title+"', '"+req.body.band_name+"', '"+req.body.audio+"')";
        let query = connection.query(sql, (err, results) => {
            if(err) throw err;
            res.redirect('/');
        });
    });
    

    reference

    0 讨论(0)
提交回复
热议问题