【发布时间】:2019-03-24 14:27:24
【问题描述】:
我正在尝试在 UI 中显示图像。
这是我的 ASP.NET Web API 核心代码。
[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");
}
我关注了这个Link 我假设上面的代码是正确的(不确定是否有更好的方法来返回图像 - 请指导我)
在组件中,我的代码如下所示。
this.service.getImageThumbnail(id).subscribe(
baseImage => {
this.thumbnail = baseImage;
},
error => (this.errorMessage = error)
);
在Service中,实现是这样的
getDesignThumbnail(id: number) {
return this.http
.get(`https://localhost:44314/api/designs/${id}/thumbnail`)
.pipe(catchError(error => this.errorHandler(error)));
}
在 HTML 中,我是这样显示的。(不确定这是否正确)
<img width="100" height="100" data-bind="attr: { src: thumbnail }" />
【问题讨论】:
-
添加
getImageThumbnail实现 -
添加逻辑
标签: angular image asp.net-web-api asp.net-core-2.0