1

Hi all I get an image that comes from the server side and shows it in the website I want to download it when download button is pressed How do I achieve this?

I have the html as follows

 <div class="row SectionRow" style="margin: 50px 0px !important;">
              <div class="col-md-6 col-sm-6 col-xs-6" style="text-align: center; margin-bottom: 20px">
                <img #imgRef2 class="ProfileImage">
                <br>
                <button type="button" (click)="DownloadProfilePic()" class="btn btn-default SigButton">Download</button>
              </div>

              <div class="col-md-6 col-sm-6 col-xs-6" style="text-align: center; margin-bottom: 20px; padding-top: 50px;">
                <img #imgRef class="SignatureImage">
                <br>
                <button type="button" class="btn btn-default SigButton">Download</button>
              </div>
            </div>

angular typescript

@ViewChild('imgRef') Signature: ElementRef;
  @ViewChild('imgRef2') ProfilePic: ElementRef;

OnInit()
{
          this.Signature.nativeElement.src = this.ImageAppDetails.AA_SIGNATURE;
          this.ProfilePic.nativeElement.src = this.ImageAppDetails.AA_PHOTO;
}

The url will be for profile pic as 'http://192.0.0.100/image.jpg'

how do I acheive this when I click the download button. Help would be appreciated.

Ashane Alvis
  • 770
  • 2
  • 18
  • 42

2 Answers2

1

Use window.open(url); to download the image

 DownloadProfilePic() { ;
    var url = this.ProfilePic.nativeElement.src 
    window.open(url);
  }
Sachila Ranawaka
  • 39,756
  • 7
  • 56
  • 80
-2

You just have to add 'download' attribute to your anchor tag. And then apply css style as required.

<a class="fa fa-download" type="button" class="btn btn-default SigButton">Download</a>
siddharth shah
  • 1,139
  • 1
  • 9
  • 17