Angular 4 direct download images

前端 未结 2 1815
隐瞒了意图╮
隐瞒了意图╮ 2020-12-22 05:37

In my angular 4 application I have a gallery with some thumbnails, every thumbnails have a download button.

I want to start the download of the image when this butto

相关标签:
2条回答
  • 2020-12-22 05:54

    Finally I use this method:

    this.mediaService.getImage(downloadLink).subscribe(
      (res) => {
            const a = document.createElement('a');
            a.href = URL.createObjectURL(res);
            a.download = title;
            document.body.appendChild(a);
            a.click();
      });
    }
    
    0 讨论(0)
  • 2020-12-22 05:55

    To direcly download the image you can try with :

    downloadImage(downloadLink) {
    
    this.mediaService.getImage(downloadLink).subscribe(
      (res) => {
        const fileURL = URL.createObjectURL(res);
        window.location.href = fileUrl;
      }
    );
    }
    
    0 讨论(0)
提交回复
热议问题