简体   繁体   English

数据损坏缓冲区到 BLOB MYSQL

[英]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.使用NodeJs,我尝试在我的应用程序POST发送的MySQL LONGBLOB中上传一个缓冲区(图像),我在我的脚本中完美接收它,但是当我将它插入我的表中时,我没有与我相同的数据有。

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我发现了我的问题,我只是在 BASE64 中对我的数据进行编码,然后用 URLENCODE 再次对其进行编码

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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