I am trying to display image in UI.
Here is my ASP.NET Web API Core Code for that.
[Route("{id:int}/image")]
public async Task<IActionResult> GetImage(int id)
{
var data = await this.designService.GetImageAsync(id);
byte[] result = data.Data;
return this.File(result, "image/jpeg");
}
I followed this Link I assume above code is correct(Not sure if there is a better way to return Image - please guide me)
In component, my code looks like this.
this.service.getImageThumbnail(id).subscribe(
baseImage => {
this.thumbnail = baseImage;
},
error => (this.errorMessage = error)
);
In Service, implementation is like this
getDesignThumbnail(id: number) {
return this.http
.get(`https://localhost:44314/api/designs/${id}/thumbnail`)
.pipe(catchError(error => this.errorHandler(error)));
}
In HTML, I am displaying like this.(Not sure if this is correct)
<img width="100" height="100" data-bind="attr: { src: thumbnail }" />

getImageThumbnailimplementation