微服务请求后端,返回二进制流文件(图片) application/octet-stream
,在ng2/ng4前端进行展示。
1.尝试使用URL.createObjectURL(response)
后添加 bypassSecurityTrustUrl
。依旧提示unsafe
//html
<img [src]="imgUrl">
//ts
getImg() {
const host = 'http://localhost:8083/';
const url2 = host + 'api/bpm-extend/repository/process-definitions/myEclipseDemo:7:227504/diagram-resource';
let firstheaders = new Headers();
firstheaders.append('Content-Type', 'image/png');
const opts: RequestOptionsArgs = {
headers: firstheaders,
responseType: 3
}
this.http.get(url2, opts).map((resp) => resp.json()).catch((err) => {throw err;})
.subscribe((val) => {
this.imgUrl = this.sanitizer.bypassSecurityTrustUrl( window.URL.createObjectURL(val) );
})
}
请问如何解决此情况?
或者是的方法错了,那有没有其他解决方案?
相关分类