Descarga de secuencia de archivos blob

  
downLoad(msg) {
    
    
    const url1 = `url`;
    this.getBlob(`${
      
      url1}`).subscribe(result => {
    
    
      this.downFile(result, 'name.zip');
    })
  }


**//post方法**
requestBlob(url: any, data?: any): Observable<any> {
    
    
    return this.http.request("post", url, {
    
     body: data, observe: 'response', responseType: 'blob' });
  }


**//get方法**
  getBlob(url: any, data?: any): Observable<any> {
    
    
    return this.http.request("get", url, {
    
     body: data, observe: 'response', responseType: 'blob' });
  }


  **// Blob文件转换下载**
  downFile(result, fileName, fileType?) {
    
    
    const data = result.body;
    const blob = new Blob([data], {
    
     type: fileType || data.type });
    const objectUrl = URL.createObjectURL(blob);
    const a = document.createElement('a');
    a.setAttribute('style', 'display:none');
    a.setAttribute('href', objectUrl);
    a.setAttribute('download', fileName);
    a.click();
    URL.revokeObjectURL(objectUrl);
  }

Supongo que te gusta

Origin blog.csdn.net/qq_43237014/article/details/107404643
Recomendado
Clasificación