简体   繁体   English

选择 Blob 返回一个函数

[英]Select Blob return a function

exports.carregaContrato = function(id, cb){
  Firebird.attach(firebirdConfig, function (err, db) {
    if (err)
      throw err;

    db.query("select contrato_escaniado as IMAGE from cad_prospectos_contratos where codigo = ?", [id], function(err, result){
      console.log(err, result[0].IMAGE)
      db.detach();
      cb(result)
    })

   })
}

I have this select from a Blob field I do not know what I'm doing wrong that the feedback I get is a function.我从 Blob 字段中选择了这个我不知道我做错了什么,我得到的反馈是一个函数。 In the console.log I have I get the following:在 console.log 中,我得到以下信息:

undefined [Function]

What I'm doing wrong, and how to solve.我做错了什么,以及如何解决。 I want to receive as a return an image that I saved converted to base64 as a string, it's like this in my bank:我想接收一个我保存为 base64 作为字符串的图像作为返回,它在我的银行中是这样的:

数据保存在银行

Solution: As my select will always return only a string I do not need for and as in the database it saves a string in base64 I just need this string using toString ()解决方案:由于我的选择将始终只返回一个我不需要的字符串,并且在数据库中它将字符串保存在 base64 中,因此我只需要使用 toString () 的字符串

result[0].IMAGE(function(err, name, eventEmitter) { 
  var buffers = []; 
  eventEmitter.on('data', function(chunk) { 
    buffers.push(chunk); 
  }); 
  eventEmitter.once('end', function() { 
    var buffer = Buffer.concat(buffers); 
    retorno = (buffer.toString()); 
    db.detach(); 
    cb(retorno) 
  }); 
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM