1
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

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
Erick Zanetti
  • 459
  • 1
  • 4
  • 11
  • I don't know node.js, but maybe this question (which also involves Firebird, node.js and blobs) can help you: https://stackoverflow.com/questions/46574826/firebird-blob-to-base64-node-js – Mark Rotteveel Dec 06 '17 at 13:15
  • And assuming you are using node-firebird, also look at https://github.com/hgourvest/node-firebird/ (specifically under [_"READING BLOBS (ASYNCHRONOUS)"_](https://github.com/hgourvest/node-firebird/#reading-blobs-asynchronous)) – Mark Rotteveel Dec 06 '17 at 13:18
  • I modified the function of the question you mentioned a little and I got it, thank you very much – Erick Zanetti Dec 06 '17 at 15:53
  • If possible, consider posting your solution as an answer, maybe it will help someone else in the future – Mark Rotteveel Dec 06 '17 at 16:00

1 Answers1

1

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) 
  }); 
});
Erick Zanetti
  • 459
  • 1
  • 4
  • 11