【发布时间】:2020-07-08 15:56:21
【问题描述】:
我想要返回带有 blobl 请求的图像,并在 html 中显示它。
我使用此代码:
<img [src]="ImageUrl"/>
这是 ts 代码:
private src$ = new BehaviorSubject(this.Url);
dataUrl$ = this.src$.subscribe(url => {
return this.imageService.GetImage(url, this.id).subscribe(data => {
this.ImageUrl=data.changingThisBreaksApplicationSecurity;
return data.changingThisBreaksApplicationSecurity
})
});
这是我的服务:
GetImage(url, id): Observable<any> {
return this.httpClient
.get(this.appConfig.apiEndpoint+ url + id, { responseType: 'blob' })
.pipe(
map(res => {
if (res) {
return this.domSanitizer.bypassSecurityTrustUrl(URL.createObjectURL(res));
}
return null;
})
)
}
但是当我需要显示图像时,它会在 html 中使用此 url:
<img src="unsafe:blob:http://localhost:4200/6868babb-5ab2-491f-b519-2f2a3d0ed351">
不要给我看任何图片。
有什么问题吗?我该如何解决这个问题????
【问题讨论】:
标签: javascript angular typescript