Node : how to convert from varbinary to image of SQL Server datatype

爷,独闯天下 提交于 2021-02-08 09:58:17

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!