【问题标题】:How to read image stored in an oracle SQL BLOB?如何读取存储在 oracle SQL BLOB 中的图像?
【发布时间】:2020-04-23 10:29:50
【问题描述】:

我正在尝试读取在 oracle SQL 数据库中存储为 blob 的图像。 以下是我目前尝试的代码:

var arrayBufferView = new Uint8Array(x.IMAGE1);
console.log(arrayBufferView)
var blob = new Blob([arrayBufferView], {type: "image/jpg"});
var urlCreator = window.URL || window.webkitURL;
var imageUrl = urlCreator.createObjectURL( blob );
var img = new Image();
img.src = imageUrl;

但是,我收到损坏的图像。我认为是因为x.IMAGE1 字段,看起来像这样:

【问题讨论】:

  • 您使用的是什么数据库库?这是在服务器端 NodeJS 脚本、客户端 Electron 脚本还是客户端/浏览器脚本中?
  • allowHalfOpen 是 Socket 对象的属性。你从哪里得到x

标签: javascript sql oracle blob


【解决方案1】:

您看到的对象是一个流,它是为 LOB 返回的默认类型。您可以使用此处记录的 API:https://oracle.github.io/node-oracledb/doc/api.html#-173-streaming-lobs

或者,您可以修改代码以将 LOB 作为缓冲区提取:https://oracle.github.io/node-oracledb/doc/api.html#getting-lobs-as-string-or-buffer-from-plsql

const result = await connection.execute(
  `BEGIN lobs_out(:id, :c, :b); END;`,
  { id: 20,
    c: {type: oracledb.STRING, dir: oracledb.BIND_OUT, maxSize: 50000},
    b: {type: oracledb.BUFFER, dir: oracledb.BIND_OUT, maxSize: 50000}
  }
);

const str = result.outBinds.c;  // a String
const buf = result.outBinds.b;  // a Buffer

. . . // do something with str and buf

【讨论】:

    猜你喜欢
    • 2015-04-02
    • 2021-01-02
    • 2012-03-05
    • 2010-12-26
    • 1970-01-01
    • 1970-01-01
    • 2016-01-18
    • 2017-04-28
    • 2019-12-31
    相关资源
    最近更新 更多