【问题标题】:BLOB field is not updating in sqlite3sqlite3 中的 BLOB 字段未更新
【发布时间】:2021-09-09 05:34:29
【问题描述】:

我开发了一个网络应用程序,可以选择将图像上传到数据库(sqlite3)。 但由于某种原因,该表在 UPDATE 命令之后没有更新。

服务器是node express。

桌子:

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);
});

图片是从vue上传的,用multer发送到服务器。

看起来是这样的:

{
  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
}

运行函数没有错误。

【问题讨论】:

    标签: node.js node-sqlite3


    【解决方案1】:

    我只需要传递文件对象的缓冲区字段

    【讨论】:

    • 请添加更多详细信息以扩展您的答案,例如工作代码或文档引用。
    • const params = [image.buffer, 2];
    猜你喜欢
    • 2022-12-03
    • 2016-01-30
    • 1970-01-01
    • 2019-08-28
    • 2019-07-29
    • 2023-03-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多