javascript - 通过安全网址以角度显示图像
问题描述
我想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">
并且不给我看任何图像。
有什么问题 ?我怎么解决这个问题 ????
解决方案
嗨,我遇到了同样的问题,但我可以通过这种方式解决它
在 html 中
<img [src]="transform(imageURI)" />
在 ts
transform(url) {
return this.domSanitizer.bypassSecurityTrustResourceUrl(url);
}
推荐阅读
- asp.net-core - 如何在 ASP.NET Core mvc 中的模型绑定上将字符串转换为值类型
- database - 如何修复 Cassandra 服务器中的“活动:活动(退出)”问题?
- reactjs - How to float a View over all Views in a screen
- python - Python IPv6 正则表达式模式识别
- java - Convert Double to Key (Priority queue)
- r - 无法使用公共 IP 访问管道工 API
- node.js - Nodejs读取大txt文件并转换编码
- ajax - 我如何知道网站使用的 API?
- javascript - 在 chart.js 的标签和数据集表中编码
- javascript - 在 for 循环中使用绑定事件