使用blob二进制流的方式下载后台文件


//url请求地址,datas传给后台的参数,fileName文件名,format文件类型后缀名如.xls
 downLoadFile(url,datas,fileName,format){
  this.http.post(url, datas, { responseType: 'blob' }).subscribe((result:any)=>{
    
const link
= document.createElement('a');
    const blob = new Blob([result], { type: 'application/zip' }); link.setAttribute(
'href', window.URL.createObjectURL(blob)); link.setAttribute('download', fileName + format); link.style.visibility = 'hidden'; document.body.appendChild(link); link.click(); document.body.removeChild(link);
}) };

注:本实例在angular6框架下实现

参考:https://blog.csdn.net/shengandshu/article/details/81127279?utm_source=blogxgwz4


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM