我的问题非常类似于这个PDF Blob - 弹出窗口没有显示内容,但我使用的是Angular 2.问题的回答是将responseType设置为arrayBuffer,但它在Angular 2中不起作用,错误是reponseType没有存在于RequestOptionsArgs类型中.我也尝试通过BrowserXhr扩展它,但仍然不起作用(https://github.com/angular/http/issues/83).
我的代码是:
createPDF(customerServiceId: string) {
console.log("Sending GET on " + this.getPDFUrl + "/" + customerServiceId);
this._http.get(this.getPDFUrl + '/' + customerServiceId).subscribe(
(data) => {
this.handleResponse(data);
});
}
Run Code Online (Sandbox Code Playgroud)
而handleResponse方法:
handleResponse(data: any) {
console.log("[Receipt service] GET PDF byte array " + JSON.stringify(data));
var file = new Blob([data._body], { type: 'application/pdf' });
var fileURL = URL.createObjectURL(file);
window.open(fileURL);
}
Run Code Online (Sandbox Code Playgroud)
我也尝试从FileSaver.js中保存方法,但是同样的问题,pdf打开,但内容不显示.谢谢
我想在img标签中显示一个图像:我这样做
零件
this.file.url=this.sanitizer.bypassSecurityTrustUrl(window.URL.createObjectURL(this.file.url));
Run Code Online (Sandbox Code Playgroud)
模板
<img [src]="file.url">
Run Code Online (Sandbox Code Playgroud)
我收到了这个错误
ERROR TypeError: Failed to execute 'createObjectURL' on 'URL': No function was found that matched the signature provided.
Run Code Online (Sandbox Code Playgroud) 我用 blob 创建了一个对象 url
let src = URL.createObjectURL(blob)
Run Code Online (Sandbox Code Playgroud)
并将其用作我的视频src属性,但会导致此错误:
GET blob:http://localhost:4200/ab3cc5aa-19cc-41f1-a4b7-55e1fa3ce85c 416 (Requested Range Not Satisfiable)
Run Code Online (Sandbox Code Playgroud)
关于如何解决这个问题的任何想法?
虽然我认为我的问题很普遍,但我使用的是 angular 2,所以准确地说,我的代码如下所示:
let src = this.sanitizer.bypassSecurityTrustUrl(URL.createObjectURL(blob));
Run Code Online (Sandbox Code Playgroud)
和模板
<video *ngFor="let videoUrl of _videos" [src]="videoUrl"></video>
Run Code Online (Sandbox Code Playgroud)
另外,我使用 angular-cli 作为我的服务器,由于这看起来像是服务器错误(?),了解它可能很有用。