I have a html page that looks like so:
<div ng-controller="DocumentCtrl">
<img ng-src="data:image/tiff;base64,{{image}}" />
</div>
My Angular controller looks like this:
angular.controller('DocumentCtrl', ['$scope', '$http', function ($scope, $http) {
$http.get('/api/Image').
then(function (response) {
$scope.image = response.data;
});
}]);
And my ApiController GET like this:
public HttpResponseMessage Get()
{
var file = HttpContext.Current.Server.MapPath("~/Images/docs/example.TIF");
var stream = new FileStream(file, FileMode.Open);
var content = new HttpResponseMessage(HttpStatusCode.OK)
{
Content = new StreamContent(stream)
};
content.Content.Headers.ContentType = new MediaTypeHeaderValue("image/tiff");
return content;
}
Inspecting the element in Chrome gives me this:
Now the data is binding to the UI correctly, but it always shows as a broken image link icon. I've tried various things, like changing the data type to image/* and using application/octet as the Content-Type, but nothing seems to make a difference.
Also, if I inspect the request with Fiddler and look at the ImageView of the response content, the image shows up there as I expect, so that portion of the process seems to be working correctly.
Is there something obvious I'm missing?
Thanks.