How can I display an image which is stored in files?

For attachments I can use the code below, but it doen't work for files.

<apex:image id="Stat1" URL="/servlet/servlet.FileDownload?file=0698E0000008w5e" width="15" height="15"/>
  • I am afraid that this can be done, there is a similar question with no answer. For Attachment the URL can be hard-coded or can be retrieved from $Action variable. As for Files, its not possible to preview it, but maybe hardcode URL to download it. – Raul Aug 7 '17 at 8:59

Try this format <apex:image url="/sfc/servlet.shepherd/version/download/[DOWNLOADID]"/>.

How to get the DOWNLOADID?

Open the File, you will get a screen as below. Hover on the download link, you will get the DOWNLOADID as highlighted. Replace [DOWNLOADID] with the ID of the ContentVersion record you want to display.


<apex:image url="/sfc/servlet.shepherd/version/download/068i0000003ebfw"/>

enter image description here

VF Page :

<apex:page standardController="Account" >
    <apex:image url="/sfc/servlet.shepherd/version/download/0680H0000036GIH"/>


enter image description here

  • This would allow an user to download file instead of a preview. – Raul Aug 7 '17 at 9:39
  • @Rahul My bad. Please find the updated answer, I somehow didn't notice that the ContentVersion ID is not exactly same as the DownloadID as explained in my answer. Thanks for the observation :) – Saroj Bera Aug 7 '17 at 11:29

Working Code, Thanks to the answer above.

My VF with a Repeat Across a list of Files:

<apex:repeat value="{!files}" var="f">
    <div class="col col-6 col-md-4 col-lg-3 col-xl-2 my_vertmargin5">
        <div class="my_padded5 my_panel">
            <apex:image url="/sfc/servlet.shepherd/version/download/{!f.ContentDocument.LatestPublishedVersionId}"
                            alt="{!f.ContentDocument.LatestPublishedVersion.Title}" height="150px"/>

My Controller Method with respect to a single record that the files are linked to:

public void GetFiles(){
    files = [SELECT Id, ContentDocumentId, ContentDocument.LatestPublishedVersionId,
    FROM ContentDocumentLink WHERE LinkedEntityId = :Job.Id];

NB: other code required like instantiating variables etc.


I've tried the solutions above with no success after few tries managed to view the image stored on files in my lightning component with similar url:

/sfc/servlet.shepherd/document/download/<YOUR FILE ID>
  • This is incorrect: it should be VERSION: <apex:image url="/sfc/servlet.shepherd/version/download/{!f.ContentDocument.LatestPublishedVersionId}" alt="{!f.ContentDocument.LatestPublishedVersion.Title}" height="150px"/> – NZ Dev Feb 11 at 9:36

Thanks @all,

I've compiled all the info I got here for others: ​​​​​​​https://www.mhamzas.com/blog/2020/01/09/use-salesforce-files-image-file-on-lwc-aura-or-vf-page-as-tag/

  • This is also incorrect, Again use "version". The higher ranked answer is correct – NZ Dev Feb 11 at 9:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.