Tony Zhao
Tony Zhao

Reputation: 81

Emojis not saved in the database using mysql and node

I want to save emojis in the database

but got an error while inserting into the database

Error: ER_TRUNCATED_WRONG_VALUE_FOR_FIELD: Incorrect string value: '\xF0\x9F\x98\x9B\xF0\x9F...' for column 'text' at row 1

Collasion I used utf8mb4_unicode_ci chatset utf8mb4 engine innodb

also I have used this in connection file

 let connection = mysql.createConnection({
        host                : _CONF.mysql.host,
        user                : _CONF.mysql.user,
        password            : _CONF.mysql.password,
        port                : _CONF.mysql.port,
        database            : _CONF.mysql.database,
        timezone            : _CONF.mysql.timezone,
        charset             : 'utf8mb4',
        collate             : 'utf8mb4_unicode_ci',
        multipleStatements  : _CONF.mysql.multipleStatements
    });

`````
I dont know what I can do next to solve my problem. It would be grateful If anyone can help me out 

Upvotes: 0

Views: 249

Answers (1)

kavigun
kavigun

Reputation: 2365

If the dataType of the column is a blob, convert the emoji to blob data and store it as a blob. If it is a string you may convert the blob to string. You use Filereader module to do so as follows.

reader.readAsText(blb);

Upvotes: 1

Related Questions