I need to display an image stored in the files of my org in alightning component. For now I just want to display an image, with its Id, not dynamically.

I tried this in my component:

<img src="{!'/servlet/servlet.FileDownload?file=0696E000000AT3BQAW'}" alt="" />

but the image is not displayed.


You need to use the ContentVersion (prefix 068), not the ContentDocument (069), then you can display it like this:

<img src="{!'/sfc/servlet.shepherd/version/download/' + v.contentVersion.Id}" />

Just remove the {!''} since you are refering to an absolute path.

<img src="/servlet/servlet.FileDownload?file=0696E000000AT3BQAW" alt="" />

  • this syntax doesn't work either... – dou Feb 13 '18 at 15:38
  • I just tested it, for me it worked. Do you get the image displayed when you open the following link? https://namespace/servlet/servlet.FileDownload?file=0696E000000AT3BQAW – Chris Feb 13 '18 at 15:51
  • no when I click the link I got an error. I'm in lightning experience but when I click the link I'm redirected to classic – dou Feb 13 '18 at 15:57
  • servlet/servlet.FileDownload?file=*Id* points to an image in Documents which is currently only accessible via Classic. When you set the namespace in the aboves link correctly you should be able to see the image. Otherwise it doesn't exist (afaik). Make sure you got the correct Id of the image. – Chris Feb 13 '18 at 16:08
  • my image exist in the files of lightning experience, not in classic... Can I access it from an url ? – dou Feb 13 '18 at 16:18

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.