如何转换 LOB(二进制图像)以发送到 Firebase 存储

How to transform a LOB (Binary image) to send to Firebase Storage

我需要return一些记录在 LOB 字段中的 Oracle 图像将它们发送到 Firebase 存储。

我正在使用带有 typescript 库的 oracledb 来调用 return 某些记录的过程。其中一个字段是 LOB(图像)。我需要 return 此数据并将此图像发送到 Firebase 存储。我不会编码。

import { IConnection } from "oracledb";
import oracledb = require("oracledb");
oracledb.fetchAsString = [ oracledb.CLOB ];

export async function uploadImages(db: IConnection) {
  const query = `
      BEGIN 
        mgglo.pck_wglo_binario.p_obter_binarios_filtro
        (
          retorno               => :retorno,
          pfiltro               => :pfiltro,
          pmod_in_codigo        => :pmod_in_codigo,
          pcodigoempreendimento => :pcodigoempreendimento,
          pcodigobloco          => :pcodigobloco,
          pcodigounidade        => :pcodigounidade
        );
      END;`;

  const bindvars = {
        retorno               : { dir: oracledb.BIND_OUT, type: oracledb.CURSOR },
        pfiltro               : 0,
        pmod_in_codigo        : 1,
        pcodigoempreendimento : 5689,
        pcodigobloco          : 9645,
        pcodigounidade        : 8966
  }

  const exec = await db.execute(query, bindvars);
  const row = await exec.outBinds["retorno"].getRow(); 
  console.log(row);

}

Return:

{ BIN_IN_CODIGO: 469,
  CAT_IN_CODIGO: 63,
  BIN_BO_ATIVO: 'S',
  BIN_ST_MIME: 'image/png',
  BIN_ST_NOME: 'Image 1.png',
  BIN_LO_BINARIO:
   Lob {
     _readableState:
      ReadableState {
        objectMode: false,
        highWaterMark: 16384,
        buffer: [Object],
        length: 0,
        pipes: null,
        pipesCount: 0,
        flowing: null,
        ended: false,
        endEmitted: false,
        reading: false,
        sync: true,
        needReadable: false,
        emittedReadable: false,
        readableListening: false,
        resumeScheduled: false,
        destroyed: false,
        defaultEncoding: 'utf8',
        awaitDrain: 0,
        readingMore: false,
        decoder: null,
        encoding: null },
     readable: true,
     domain: null,
     _events: { end: [Object], finish: [Object] },
     _eventsCount: 2,
     _maxListeners: undefined,
     _writableState:
      WritableState {
        objectMode: false,
        highWaterMark: 16384,
        finalCalled: false,
        needDrain: false,
        ending: false,
        ended: false,
        finished: false,
        destroyed: false,
        decodeStrings: true,
        defaultEncoding: 'utf8',
        length: 0,
        writing: false,
        corked: 0,
        sync: true,
        bufferProcessing: false,
        onwrite: [Function: bound onwrite],
        writecb: null,
        writelen: 0,
        bufferedRequest: null,
        lastBufferedRequest: null,
        pendingcb: 0,
        prefinished: false,
        errorEmitted: false,
        bufferedRequestCount: 0,
        corkedRequestsFree: [Object] },
     writable: true,
     allowHalfOpen: true,
     iLob:
      ILob {
        valid: true,
        autoCloseLob: true,
        type: 2007,
        offset: 1,
        pieceSize: 8060,
        length: 814115,
        chunkSize: 8060 },
     close: [Function] },
  BIN_ST_DESCRICAO: 'Teste Valmir',
  BIN_DT_CRIACAO: 2019-05-28T13:32:37.000Z,
  BIN_BO_LINK: 'N' }



FIELD: BIN_LO_BINARIO

LOB 作为 Lob 实例出现。这可用于流式传输大型对象,但如果 LOB 相对较小(与 Node.js 进程有权访问的内存量相比),则可以覆盖默认值以获取和 String 或 Buffer,具体取决于是否LOB 是 BLOB 或 CLOB。

这是一个从 this post 中提取 BLOB 作为缓冲区的示例:

const getSql =
 `select file_name "file_name",
    dbms_lob.getlength(blob_data) "file_length",
    content_type "content_type",
    blob_data "blob_data"
  from jsao_files
  where id = :id`;

async function get(id) {
  const binds = {
    id: id
  };
  const opts = {
    fetchInfo: {
      blob_data: {
        type: oracledb.BUFFER
      }
    }
  };

  const result = await database.simpleExecute(getSql, binds, opts);

  return result.rows;
}