在 Node.js 中从 Oracle 数据库读取 BLOB
Read BLOB from Oracle Database in Node.js
我正在尝试使用名为 oracledb
的 npm 包中的 nodejs 从 Oracle 读取 BLOB
数据类型,这是我的 select 语句,其中包含图片:
select media from test_data
我试过一些解决方案,但都不管用。
这是我在 res.json
中的回复:
{
"MEDIA": {
"_readableState": {
"objectMode": false,
"highWaterMark": 16384,
"buffer": {
"head": null,
"tail": null,
"length": 0
},
"length": 0,
"pipes": [],
"flowing": null,
"ended": false,
"endEmitted": false,
.....
},
如何获取它的十六进制值?
您正在查看可以从中流式传输的 node-oracledb Lob class 实例。
但是,直接获取缓冲区可能是最简单的方法。通过设置 oracledb.fetchAsBuffer
来做到这一点,例如:
oracledb.fetchAsBuffer = [ oracledb.BLOB ];
const result = await connection.execute(`SELECT b FROM mylobs WHERE id = 2`);
if (result.rows.length === 0)
console.error("No results");
else {
const blob = result.rows[0][0];
console.log(blob.toString()); // assuming printable characters
}
我正在尝试使用名为 oracledb
的 npm 包中的 nodejs 从 Oracle 读取 BLOB
数据类型,这是我的 select 语句,其中包含图片:
select media from test_data
我试过一些解决方案,但都不管用。
这是我在 res.json
中的回复:
{
"MEDIA": {
"_readableState": {
"objectMode": false,
"highWaterMark": 16384,
"buffer": {
"head": null,
"tail": null,
"length": 0
},
"length": 0,
"pipes": [],
"flowing": null,
"ended": false,
"endEmitted": false,
.....
},
如何获取它的十六进制值?
您正在查看可以从中流式传输的 node-oracledb Lob class 实例。
但是,直接获取缓冲区可能是最简单的方法。通过设置 oracledb.fetchAsBuffer
来做到这一点,例如:
oracledb.fetchAsBuffer = [ oracledb.BLOB ];
const result = await connection.execute(`SELECT b FROM mylobs WHERE id = 2`);
if (result.rows.length === 0)
console.error("No results");
else {
const blob = result.rows[0][0];
console.log(blob.toString()); // assuming printable characters
}