Node:如何从varbinary转换为SQL Server数据类型的映像 [英] Node : how to convert from varbinary to image of SQL Server datatype

查看:57
本文介绍了Node:如何从varbinary转换为SQL Server数据类型的映像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个SQL Server数据库,图像类型为 varbinary .我需要转换 varbinary 并将图像返回到网页.帮助将不胜感激.

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.

我发现了这一点,它非常有帮助,但是我需要反过来. Node.js如何从MS Sql服务器数据类型的varbinary转换为图像

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

类似...

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());
    
   }

推荐答案

这就是答案.

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

这篇关于Node:如何从varbinary转换为SQL Server数据类型的映像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆