0

I am a beginner with node.js and I would ask you for advice. In MSSQL images are stored as varbinary enter link description here. I have written over the application in nodejs that allows access to data. I need to select images from the database, converted from varbinary to image and change their quality and re-save them as varbinary. It is the building plans enter link description here, which have a size 1.5 - 3 MB, and I need it to shrink.

user3468921
  • 561
  • 2
  • 8
  • 26

1 Answers1

0

sql.VarBinary data type will map to a buffer in node.js.

JS Data Type To SQL Data Type Map

  • String -> sql.NVarChar
  • Number -> sql.Int
  • Boolean -> sql.Bit
  • Date -> sql.DateTime
  • Buffer -> sql.VarBinary
  • sql.Table -> sql.TVP

When you retrieve your binary image data from the database, you can create a buffer.

var b64str = /* data fetched from the database */;
var buf = new Buffer(b64str, 'base64');

You should be able to send the image as a buffer back to the database, if you are using the mssql package

request.input('input_parameter', sql.VarBinary, buf);
svnm
  • 22,878
  • 21
  • 90
  • 105