AngularJS显示图像斑点 [英] Angularjs showing image blob
本文介绍了AngularJS显示图像斑点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一种调用API并获取响应的方法.一个api返回图像.内容类型:应用程序/八位字节流 如果我将responseType设置为"blob",则可以正常工作.
I have a method to call APIs and get responses. One api returning an image. Content-Type:application/octet-stream If I set responseType: "blob", it is working fine.
$http({
url: apiConstants.BASE_URL + 'login',
method: "POST",
responseType: "blob",
data: {
"Req": req
},
headers: {
'X-Username': aUser,
'X-Password': aPass,
},
}).success(function(data, status, headers, config) {
var URL = $window.URL || $window.webkitURL;
$rootScope.ImageSrc = URL.createObjectURL(data);
}
但是我想从请求中删除responseType:"blob",并尝试以以下方式创建blob
But I want to remove responseType: "blob" from the request and trying to create the blob in following way
$http({
url: apiConstants.BASE_URL + 'login',
method: "POST",
data: {
"Req": req
},
headers: {
'X-Username': aUser,
'X-Password': aPass,
},
}).success(function(data, status, headers, config) {
var blob = new Blob(
[data],
{
type: 'application/octet-stream'
}
);
var URL = $window.URL || $window.webkitURL;
$rootScope.ImageSrc = URL.createObjectURL(blob);
}
但是图像未显示在html中.这是html代码
But image is not showing in the html. this is the html code
<img class="img-responsive empImg" id="empImage" data-ng-src="{{ImageSrc}}" />
您能为此建议我吗
推荐答案
image/png; base64
image/png;base64
将其设置为您的响应类型.
Set that as your response type.
这篇关于AngularJS显示图像斑点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文