How do I retrieve and view an image from an SQL Server database saved as varbinary

Viewed 26

I'm a newbie developer and I've made a code in Node.js to insert an image as varbinary into an SQL Server DB, now I would like to retrieve this image and see it.

For now I just want to be able to see the image, with or without code, so I can figure out my next steps. Here's the code I've written:


var dbConfig = {
    server: "localhost\\MSSQLSERVER",
    database: "nodeapp",
    user: "test",
    password: "1234",
    port: 1433,
    synchronize: true,
    trustServerCertificate: true
};

var con = new sql.ConnectionPool(dbConfig);

con.connect(function(err) {
  if (err) throw err;
  console.log("Connected!");
  var sql = "INSERT INTO teste (id,nome,img) SELECT 1,'lizzy', BULKCOLUMN FROM OPENROWSET (BULK 'C:\\Users\\lab101a\\Documents\\Mateus\\lizzy.jpeg', Single_Blob)  as varbinary";
  con.query(sql, function (err, result) {
    if (err) throw err;
    console.log("1 record inserted");
  });
});
0 Answers
Related