I develop a web app with option to upload an image to database(sqlite3). but from some reason the table is not updated after the UPDATE command.
The server is node express.
The table:
CREATE TABLE USER (
id INTEGER PRIMARY KEY AUTOINCREMENT,
isAdmin BOOLEAN,
firstName TEXT,
lastName TEXT,
userName TEXT UNIQUE,
image BLOB,
password TEXT NOT NULL
);
const db = new sqlite3.Database('./database/' + conf.dbName);
const image = .......;
const stmt = 'UPDATE USER SET image=? WHERE id = ?';
const params = [image, 2];
db.run(stmt, params, (error, result) => {
if (error) {
return rej(error.message);
}
return res(result);
});
The image was uploaded from vue and sent to the server with multer.
This is how it looks like:
{
fieldname: 'image',
originalname: '2021-09-04.png',
encoding: '7bit',
mimetype: 'image/png',
buffer: <Buffer 89 50 4e 47 0d 0a 1a 0a 00 00 00 0d 49 48 44 52 00 00 07 80 00 00 04 38 08 06 00 00 00 e8 d3 c1 43 00 00 00 01 73 52 47 42 00 ae ce 1c e9 00 00 00 04 ... 199558 more
bytes>,
size: 199608
}
There is no error from the run function.
I just needed to pass the buffer field of the file object