Select Blob return a function

759 Views Asked by At
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. In the console.log I have I get the following:

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:

data saved in the bank

1

There are 1 best solutions below

0
Erick Zanetti On

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 ()

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) 
  }); 
});