I'm trying to get some blob files (images) and then display it on the screen using base64.
This is my node.js code:
var queryimage = "SELECT iproduct FROM images";
connection.query(queryimage, function(err, rows, fields){
socket.emit('image_prova', new Buffer(rows, 'binary').toString('base64'));
});
Then I'm getting the suposed string:
websocket.on('image_prova', function(data){
$('#imagehere').append('<img src=data:image/jpeg;base64,'+data+' />');
});
The image is not being displayed and the string given is: AA==
I don't understand why...!
You are passing rows instead of rows[0] to Buffer. You only requested one, but it is still an array, so you need to access the one you actually want.
If that doesn't work, let me know.