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);
}
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);
}
But image is not showing in the html. this is the html code
<img class="img-responsive empImg" id="empImage" data-ng-src="{{ImageSrc}}" />
Could you please advise me on this