简体   繁体   中英

Data corrupted Buffer to BLOB MYSQL

With NodeJs, I try to upload a buffer (image) in my MySQL LONGBLOB sent by a POST of my application, i receive it perfecly in my script, but when I insert it in my table, I dont have the same data than what i had.

Can you explain me why?

 var query = "INSERT INTO categorie (nom_categorie"; // FIELD if (req.body.def_categorie) query += ",def_categorie"; if (req.body.idplat) query += ",idplat"; if (req.body.idmenu) query += ",idmenu"; if (req.body.image_categorie) query += ",image_categorie"; query += ")"; query += " VALUES (" + pool.escape(req.body.nom_categorie); // VALUES (Echappement des caractères pour empécher les injections SQL if (req.body.def_categorie) query += "," + pool.escape(req.body.def_categorie); if (req.body.idplat) query += "," + pool.escape(req.body.idplat); if (req.body.idmenu) query += "," + pool.escape(req.body.idmenu); if (req.body.image_categorie) query += "," + Buffer.from(req.body.image_categorie, "utf8"); query += ")"; pool.query(query, null, function (err, results) { if (err) { pool.end(); res.status(500).send(err); } else { pool.end(); res.header("Access-Control-Allow-Origin", "*"); res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept"); res.send(results); } });

File i send: 文件发送

File in my DB: 文件数据库

I found my problem, i just encode my data in BASE64 and i encode it again with an URLENCODE

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM