前端解决浏览器下载文件名称问题

时间:2024-02-19 20:27:01
// 下载doc url
let href = “base64编码”
let fileName = "文件名.doc
// 下载 doc
this.http.get(href, {
  observe: \'response\',
  responseType: \'blob\',
}).subscribe(res:Blob => {
// 返回的数据流为Blob
const file = decodeURIComponent(fileName); this._FileSaverService.save(res.body, file); this.isDownload = false; }, err => { this.isDownload = false; this.message.create(\'error\', \'下载失败!\'); });