来自 Nodejs 的 Base 64 使用 oracledb 查询 blob 数据 returns 空缓冲区
Base 64 from Nodejs using oracledb to query blob data returns empty buffer
blob contents - PHN2ZyB3aWR0aD0iMjQiIGhlaWdodD0iMjQiIHZpZXdCb3g9IjAgMCAyNCAyNCIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiBmb2N1c2FibGU9ImZhbHNlIj48cGF0aCBkPSJNMTIgMWM2LjA3NCAwIDEwLjk5OSA0LjkyNSAxMC45OTkgMTEgMCA2LjA3NC00LjkyNSAxMC45OTktMTEgMTAuOTk5LTYuMDc0IDAtMTAuOTk5LTQuOTI1LTEwLjk5OS0xMUMxIDUuOTI1IDUuOTI1IDEgMTIgMXptMCAxOC4xNzNhNy4xNzQgNy4xNzQgMCAxMC0uMDAxLTE0LjM0NyA3LjE3NCA3LjE3NCAwIDAwMCAxNC4zNDd6bTAtMy42NTNhMy41MiAzLjUyIDAgMTEwLTcuMDQgMy41MiAzLjUyIDAgMDEwIDcuMDR6IiBmaWxsLXJ1bGU9ImV2ZW5vZGQiPjwvcGF0aD48L3N2Zz4K
const chainNumber = req.params.chainNumber;
try {
connection.execute(
`select logo
from chain_logos
where chain_id = :1`,
[chainNumber], {
outFormat: oracledb.ARRAYBUFFER
},
async function(err, result) {
if (err) {
console.error(err.message);
return;
}
connection.close();
const data = result.rows.map(row => ({
logo: Buffer.from(row[0]).toString('base64'),
logo2: Buffer.from(row[0], 'base64'),
logo3: row[0]
}))
return res.send({ data });
});
} catch (err) {
console.log('Error: ', err);
return res.send(`error returning chain logo`);
}
即使有 blob 数据,我也只看到代码返回了一个空缓冲区:
{“数据”:[{“标志”:“==”,“标志2”:{“类型”:“缓冲区”,“数据”:[0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,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adable":false,"emittedReadable ":false,"readableListening":false,"resumeScheduled":false,"errorEmitted":false,"emitClose":true,"autoDestroy":true,"destroyed":false,"errored":null,"closed": false,“closeEmitted”:false,“defaultEncoding”:“utf8”,“awaitDrainWriters”:null,“multiAwaitDrain”:false,“readingMore”:false,“decoder”:null,“encoding”:null},“_events” :{},"_eventsCount":1,"_writableState":{"objectMode":false,"highWaterMark":16384,"finalCalled":false,"needDrain":false,"ending":false,"ended":false "finished":false,"destroyed":false,"decodeStrings":false,"defaultEncoding":"utf8","length":0,"writing":false,"corked":0,"sync":true “bufferProcessing”:false,“writecb”:null,“writelen”:0,“afterWriteTickInfo”:null,“buffered”:[],“bufferedIndex”:0,“allBuffers”:true,“allNoop”:true, “pendingcb”:0,“prefinished”:false,“errorEmitted”:false,“emitClose”:true,“autoDestroy”:true,“errored”:null,“closed”:false},“allowHalfOpen”:true,” offset":1,"_isActive":false,"_parentObj":{"_rowCache":[],"_processingStarted":false,"_convertedToStream":false,"_a llowGetRowCall":false,"_isActive":false,"_parentObj":{"_events":{},"_eventsCount":1,"_dbObjectClasses":{},"_requestQueue":[],"_inProgress":true," _pool":{"_events":{},"_eventsCount":2,"_queueTimeout":60000,"_queueMax":500,"_enableStatistics":false,"edition":"","events":false,"externalAuth ":false,"homogeneous":true,"user":...
默认情况下,LOBS 将 return 作为对象,您可以从中流式传输,或者可以调用 getData()
。
如果您的 LOB 为 1 GB 或更小,那么您可能希望强制所有 LOB return编辑为字符串或缓冲区。在您的代码顶部设置这些:
oracledb.fetchAsString = [ oracledb.CLOB ];
oracledb.fetchAsBuffer = [ oracledb.BLOB ];
阅读 Working with CLOB, NCLOB and BLOB Data 上的文档了解更多详情。
outformat
属性是指行是用数组还是JS对象表示。没有预定义常量 oracledb.ARRAYBUFFER
。或者也许您自己添加了这个常量?
blob contents - PHN2ZyB3aWR0aD0iMjQiIGhlaWdodD0iMjQiIHZpZXdCb3g9IjAgMCAyNCAyNCIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiBmb2N1c2FibGU9ImZhbHNlIj48cGF0aCBkPSJNMTIgMWM2LjA3NCAwIDEwLjk5OSA0LjkyNSAxMC45OTkgMTEgMCA2LjA3NC00LjkyNSAxMC45OTktMTEgMTAuOTk5LTYuMDc0IDAtMTAuOTk5LTQuOTI1LTEwLjk5OS0xMUMxIDUuOTI1IDUuOTI1IDEgMTIgMXptMCAxOC4xNzNhNy4xNzQgNy4xNzQgMCAxMC0uMDAxLTE0LjM0NyA3LjE3NCA3LjE3NCAwIDAwMCAxNC4zNDd6bTAtMy42NTNhMy41MiAzLjUyIDAgMTEwLTcuMDQgMy41MiAzLjUyIDAgMDEwIDcuMDR6IiBmaWxsLXJ1bGU9ImV2ZW5vZGQiPjwvcGF0aD48L3N2Zz4K
const chainNumber = req.params.chainNumber;
try {
connection.execute(
`select logo
from chain_logos
where chain_id = :1`,
[chainNumber], {
outFormat: oracledb.ARRAYBUFFER
},
async function(err, result) {
if (err) {
console.error(err.message);
return;
}
connection.close();
const data = result.rows.map(row => ({
logo: Buffer.from(row[0]).toString('base64'),
logo2: Buffer.from(row[0], 'base64'),
logo3: row[0]
}))
return res.send({ data });
});
} catch (err) {
console.log('Error: ', err);
return res.send(`error returning chain logo`);
}
即使有 blob 数据,我也只看到代码返回了一个空缓冲区: {“数据”:[{“标志”:“==”,“标志2”:{“类型”:“缓冲区”,“数据”:[0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0 ,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 ,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 ,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 ,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 ,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 ,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 ,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 ,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 ,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 ,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 ,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 ,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 ,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 ,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 ,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]} ,"logo3":{"_readableState":{"objectMode":false,"highWaterMark":16384,"buffer":{"head":null,"tail":null,"length":0},"length" :0,"pipes":[],"flowing":null,"ended":false,"endEmitted":false,"reading":false,"sync":true,"needReadable":false,"emittedReadable ":false,"readableListening":false,"resumeScheduled":false,"errorEmitted":false,"emitClose":true,"autoDestroy":true,"destroyed":false,"errored":null,"closed": false,“closeEmitted”:false,“defaultEncoding”:“utf8”,“awaitDrainWriters”:null,“multiAwaitDrain”:false,“readingMore”:false,“decoder”:null,“encoding”:null},“_events” :{},"_eventsCount":1,"_writableState":{"objectMode":false,"highWaterMark":16384,"finalCalled":false,"needDrain":false,"ending":false,"ended":false "finished":false,"destroyed":false,"decodeStrings":false,"defaultEncoding":"utf8","length":0,"writing":false,"corked":0,"sync":true “bufferProcessing”:false,“writecb”:null,“writelen”:0,“afterWriteTickInfo”:null,“buffered”:[],“bufferedIndex”:0,“allBuffers”:true,“allNoop”:true, “pendingcb”:0,“prefinished”:false,“errorEmitted”:false,“emitClose”:true,“autoDestroy”:true,“errored”:null,“closed”:false},“allowHalfOpen”:true,” offset":1,"_isActive":false,"_parentObj":{"_rowCache":[],"_processingStarted":false,"_convertedToStream":false,"_a llowGetRowCall":false,"_isActive":false,"_parentObj":{"_events":{},"_eventsCount":1,"_dbObjectClasses":{},"_requestQueue":[],"_inProgress":true," _pool":{"_events":{},"_eventsCount":2,"_queueTimeout":60000,"_queueMax":500,"_enableStatistics":false,"edition":"","events":false,"externalAuth ":false,"homogeneous":true,"user":...
默认情况下,LOBS 将 return 作为对象,您可以从中流式传输,或者可以调用 getData()
。
如果您的 LOB 为 1 GB 或更小,那么您可能希望强制所有 LOB return编辑为字符串或缓冲区。在您的代码顶部设置这些:
oracledb.fetchAsString = [ oracledb.CLOB ];
oracledb.fetchAsBuffer = [ oracledb.BLOB ];
阅读 Working with CLOB, NCLOB and BLOB Data 上的文档了解更多详情。
outformat
属性是指行是用数组还是JS对象表示。没有预定义常量 oracledb.ARRAYBUFFER
。或者也许您自己添加了这个常量?