【问题标题】:How to download file in angular in exact extension如何以精确的扩展名下载角度文件
【发布时间】:2020-02-15 10:15:13
【问题描述】:

我想使用 hardcord 通过 HTML 标签从服务器下载文件

status.html

<ion-col size="2" style="border-right:none;" >

 <ng-container *ngFor="let doc of document; ">

  <a href="http://myinnovativetest.com/CR/uploads/{{doc}}" 


(click)="download(doc)"  download>

  {{doc}}

</a><br />
      </ng-container>

file.service.ts

downloadFile(): Observable<any>{        

return this.http.get('http://myinnovativetest.com/CR/uploads', { 

responseType: ResponseContentType.Blob });

  }

status.ts

download(doc){
  this.fileService.downloadFile().subscribe(response => {

window.location.href = response.url;

 console.log(response.url)

 }), error => console.log('Error downloading the file'),

 () => console.info('File downloaded successfully');

//console.log("hello")
}

我希望下载文件 download.jpg,但它下载为 download.html

【问题讨论】:

    标签: php angular ionic-framework


    【解决方案1】:

    您可以使用File-Saver

    import { saveAs } from 'file-saver';

    download(doc) {
        this.fileService.downloadFile().subscribe(response => {
    
          FileSaver.saveAs(response, "data.pdf");
    
        }), error => console.log('Error downloading the file'),
    
          () => console.info('File downloaded successfully');
    
      }
    

    【讨论】:

      猜你喜欢
      • 2021-01-25
      • 1970-01-01
      • 2018-10-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-03-04
      相关资源
      最近更新 更多