在Angular的new选项卡中打开PDF



我正在下载angular8和spring boot的文件。我想把保存在新选项卡中的PDF文件打开,你能帮我吗?

FileDownload(fileId: number, headers): Observable<any> {
return this.http.get(apiHost + '/downloadFile/' + fileId, { headers, responseType: 'blob' as 'json' });
}

downloadFile(event): void {
const headers = new HttpHeaders();
this.service.FileDownload(event.fileId, headers).subscribe(response => {
let dataType = response.type;
let binaryData = [];
binaryData.push(response);
let downloadLink = document.createElement('a');
downloadLink.href = window.URL.createObjectURL(new Blob(binaryData, { type: dataType }));
if (event.fileName)
downloadLink.setAttribute('download', event.fileName);
document.body.appendChild(downloadLink);
downloadLink.click();
})

}

更新(工作代码)

this.service.FileDownload(event.fileId, headers).subscribe(response => {
let dataType = response.type;
let binaryData = [];
binaryData.push(response);
const fileURL = URL.createObjectURL(new Blob(binaryData, { type: dataType }));
window.open(fileURL, '_blank');

})

Spring Booot (inline)
response.setHeader("Content-Disposition", String.format("inline; filename="%s"", fileName));

window.open(downloadLink. exe)href,"平等")

最新更新