0

I am in need of downloading an file may be it is image or pdf. For this I have written below code.

<a href="https://localhost:44344/UploadedFiles/IMG_20190314_205925_3be1d2b3-3bac-4184-8468-995d58d5ff80.jpg">Downlod image</a>

and

<a [routerLink]="https://localhost:44344/UploadedFiles/IMG_20190314_205925_3be1d2b3-3bac-4184-8468-995d58d5ff80.jpg">Downlod image</a>

Both are opening image in same tab, but not direct downloading. I did not find any support for this on google, youtube etc.

How can I do it?

GOPAL SHARMA
  • 657
  • 2
  • 12
  • 37
  • Possible duplicate of [href image link download on click](https://stackoverflow.com/questions/2408146/href-image-link-download-on-click) – jonrsharpe Apr 03 '19 at 07:01
  • @jonrsharpe - It is not working. I want to download any type of file, be it image or pdf. not just image. help me on this. don't downvote my question. you can try this in angular 7, the tricks in given link not working. – GOPAL SHARMA Apr 03 '19 at 07:40
  • @jonrsharpe - My question is not duplicate, I have clearly mention "Angular 7". – GOPAL SHARMA Apr 03 '19 at 07:42
  • 2
    Why do you think it matters that you're using Angular, 7 or otherwise? The behaviour you're describing is the same with hand-written HTML, the same fixes can be applied to your template. And what specifically *"is not working"* - have you tried something different to what you posted? – jonrsharpe Apr 03 '19 at 07:45
  • @jonrsharpe - Off course yes, I have tried but the behavior is same, it is opening in same tab instead of downloading. – GOPAL SHARMA Apr 03 '19 at 07:51
  • @GopalSharma jonrsharpe is right, the way you are trying to download that file is the standard HTML behaviour so the question he linked should solve your issue. If you are looking for a way to download a file via HTTP request instead, you can find a question (and an answer I wrote some months ago) about it here: https://stackoverflow.com/q/50332447/9653205 – Deadpool Apr 03 '19 at 07:55

1 Answers1

0

The behavior you are using for both the tags are same, instead of downloading it will open the link.

Please use blob object to download the image, see the example in this link given below:- https://www.google.com/amp/s/blog.mikehodnick.com/angular-download-image-blob-and-bind-to-img/amp/

Shilpa Soni
  • 306
  • 3
  • 7