I am accessing third party database where there are images stored in varbinary column. I am writing node.js application to restore varbinary images stored in MS Sql server into .jpg file.
When I query varbinary is returned as buffer but from buffer I am not able to restore image into .jpg file.
For MS Sql server access i am using https://www.npmjs.com/package/mssql libray.
[UPDATE:]: Below are the some of the ways I tried to convert and save as Image.
var decodedImage = new Buffer(varbinaryBufferReturedFromDatabase, 'base64');
var decodedImage = new Buffer(varbinaryBufferReturedFromDatabase, 'hex');
var decodedImage = new Buffer(varbinaryBufferReturedFromDatabase, 'uft8');
var decodedImage = varbinaryBufferReturedFromDatabase.toString('hex');
var decodedImage = varbinaryBufferReturedFromDatabase.toString('base64');
var decodedImage = varbinaryBufferReturedFromDatabase.toString('uft8');
fs.writeFile(__dirname+'/../public/images/img3.jpg', decodedImage, function(err, data){
if (err) throw err;
console.log('It\'s saved!');
cb(data);
});