I want to insert a base64 string into a mysql blog. To do it, I use the code below but when I run the code I have the following error:
ER_DATA_TOO_LONG: Data too long for column 'Immagine' at row 1
Immagine is base64 image(png or jpg)
Node.js Code:
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;
}
base64string -imgCastis aBuffer. Of what type isImagine?Immaginecolumn? And second try like this :const imgCast = new Buffer.from(Immagine).toString('base64').