问题描述
This is my API call In **report.service.ts**
downloadReport(id) :Observable<HttpResponse<Blob>>{
return this.http.get<Blob>(environment.baseUrl + 'files?id='+id,{
observe: 'response',responseType: 'blob' as 'json'
});
}
call in **report.componenet.ts** file
this.reportsService.downloadReport(arg.fileName).subscribe((data) => {
console.log(data.headers.get('content-disposition'));
let d = data.body
let blob = new Blob([d],{type: 'application/pdf'});
var downloadURL = window.URL.createObjectURL(d);
var link = document.createElement('a');
link.href = downloadURL;
link.download = "report.pdf";
link.click();
})
文件正在正确下载,但无法获取文件名 因此我可以在这里 link.download =“ report.pdf”; 替换为动态文件名
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)