0

I'm have a SQL Server database with images of type varbinary. I need to convert the varbinary and return the image to a web page. Help would be appreciated.

I found this and it was very helpful, but I need it in reverse. Node.js How to convert to image from varbinary of MS Sql server datatype

Something like ...

var image  = new Buffer(rs.recordset[0].Image).toString('base64');
                    res.type('image/jpeg; charset=utf-8');
                    res.status(200).end(image);
<ng-template ngbSlide *ngFor="let image of images">
          <img class="center-block" src="data:image/JPEG;base64,{{image}}">
        </ng-template>

And my service is like this ...

 getImage(query){
    
       return this._http.get(this.API_URL + this.baseUrl + query)
         .map(res => res.json());
    
   }
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
theTechGrandma
  • 103
  • 1
  • 13
  • 1
    may this link help you https://stackoverflow.com/questions/14667553/node-js-convert-variable-length-binary-data-to-jpeg-or-png – ZearaeZ Aug 03 '17 at 05:44

1 Answers1

1

This was the answer.

res.writeHead(200, {'Content-Type': 'image/jpeg'});
//var image = rs;
var image  = new Buffer(rs.recordset[0].Image);
res.end(image);
theTechGrandma
  • 103
  • 1
  • 13