使用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