1. angualr 用post请求二进制文件(PDF)的接口服务
// 文件预览
previewHelpFile(fileName:string): Observable<HttpResponse<ArrayBuffer>> {
const url = `接口地址`;
return this._http.post(url, {}, { responseType: 'arraybuffer', observe: 'response' })
.pipe(
map(res => res)
)
}
2. angular 处理后端返回的二进制流(PDF),并在页面上预览显示
// Ionic2和TypeScript中对外部url资源链接做了安全限制,所以得使用这个类处理地址
import { DomSanitizer } from '@angular/platform-browser';
// 获取预览文件
public getPreviewFile(fileName): void {
this._getHelpFile.previewHelpFile(fileName).subscribe(res => {
let blob = new Blob([res.body], {type: 'application/pdf'})
let url = window.URL.createObjectURL(blob)
this.myfiles = this._domSanitizer.bypassSecurityTrustResourceUrl(url)
})
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。