I am currently trying to download an image file from an attachment object. I am able to download the file with the following code <a href="{!URLFOR($Action.Attachment.Download, att.Id)}" download="{!att.Name}.jpg" target="_blank">{!att.Name}</a> but the file always comes without the extension. Any solutions?

  • 1
    What is the value of {!att.Name}? When looking at it in a System.debug log, does it have the file extension? Commented Sep 23, 2016 at 16:24
  • No it doesn't, it shows only the file name. And when i try to rename it its overwrited with the original name.
    – user37586
    Commented Sep 26, 2016 at 8:27

1 Answer 1


As far as I know the download attribute is now supported by all the major browsers and should work. I tried doing

<apex:page standardController="Attachment" docType="html-5.0">
    <a href="{!URLFOR($Action.Attachment.Download, Attachment.Id)}" download="{!Attachment.Name}" target="_blank">{!Attachment.Name}</a>

Seems to be working as expected.

What could be happening for you

  1. Probably extenstions are set to be hidden in the OS ?
  2. Generally files are saved with the extenstion in the name, might be something wrong with your file that you were testing with, try using another file

files with extention

  • I have my OS set to show extensions, so that's not the problem. The second point seems to be the problem, i'm trying a workaround but with no success. When i try to rename the file it doesn't work. Supposedly the param that the download attribute receives is the name that the downloaded file comes with, but it comes with its original name (without the extension).
    – user37586
    Commented Sep 26, 2016 at 10:08
  • Try using some other image may be like jpeg.org/images/jpeg-home.jpg ?
    – Avidev9
    Commented Sep 26, 2016 at 10:13
  • With the extension the path to the file can not be found. If i manually change the name of the file and add the extension, the download works just fine. But if there would be a way for me to change this name in the a tag it would save me a lot of time. I think that it is overwritten by a definition in the browser. Is there anyway i can work around this definition?
    – user37586
    Commented Sep 26, 2016 at 10:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .