【发布时间】:2021-01-23 08:03:05
【问题描述】:
我想在 mysql 博客中插入一个 base64 字符串。为此,我使用下面的代码,但是当我运行代码时出现以下错误:
ER_DATA_TOO_LONG:第 1 行的“Immagine”列的数据太长
想象是base64图像(png或jpg)
Node.js 代码:
async function inserimentoTipologia(Nome, Immagine) {
var ret = true;
var imgCast = new Buffer.from(Immagine, "base64");
checkValueLoad = await new Promise((resolve, reject) => {
return db.con.query("Insert into Categoria(Nome,Immagine) values( ? , ? ); ", [Nome, imgCast], function(err, results) {
if (err) {
ManageError.SendError("Errore: nella funzione inserimentoTipologia " + err);
ret = false;
}
resolve(true);
});
});
return ret;
}
【问题讨论】:
-
您没有插入
base64字符串 -imgCast是Buffer。Imagine是什么类型的? -
同意@eol。 .您为
Immagine列设置了什么类型?第二次尝试这样:const imgCast = new Buffer.from(Immagine).toString('base64'). -
想象是base64 png