0

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;
}
3
  • 1
    Your not inserting a base64 string - imgCast is a Buffer. Of what type is Imagine? Commented Oct 8, 2020 at 9:44
  • Agree with @eol. . What type you set for Immagine column? And second try like this : const imgCast = new Buffer.from(Immagine).toString('base64'). Commented Oct 8, 2020 at 9:45
  • immagine is base64 png Commented Oct 8, 2020 at 9:55

1 Answer 1

1
    var ret = true;
    checkValueLoad = await new Promise((resolve, reject) => {
        return db.con.query("Insert into Categoria(Nome,Immagine) values( ? , ? ); ", [Nome, Buffer.from(Immagine).toString('base64')], function(err, results) {
            if (err) {
                ManageError.SendError("Errore: nella funzione inserimentoTipologia " + err);
                ret = false;
            }
            resolve(true);
        });
    });
    return ret;
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.