4

I have following code as below in html file that uses asp.net. If the file is any other than the image file, it downloads automatically. But if the file is image, it opens it in tab and then we have to manually download it. How can I automate this process without prompting user to do so manually? And the values of URL and Filename come from database.

<a href="${URL}" download="${FileName}">
   <img 
      src="../Images/Download.png" 
      title="Click here to download the attachment." 
    />
</a>
RohrerF
  • 33
  • 1
  • 10
Komal R
  • 387
  • 2
  • 16
  • i don't see an issue with this. if you have correct `href="path/to/image"` https://www.w3schools.com/tags/tryit.asp?filename=tryhtml5_a_download2 shows an example – Andrejs Gubars Feb 13 '19 at 12:08
  • Make sure that the image doesn't have a `Content-Disposition: inline` header (see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#Attributes in the "notes" section). – thibpat Feb 13 '19 at 12:09

1 Answers1

1

To download an image, use this syntax:

<a href="${Filename}" download="download">
Jack Bashford
  • 43,180
  • 11
  • 50
  • 79