问题
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());
}
回答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);
来源:https://stackoverflow.com/questions/45473672/node-how-to-convert-from-varbinary-to-image-of-sql-server-datatype