Search code examples
htmlsalesforcesalesforce-lightninglwc

Display attachment in LWC


I'm trying to display a image stored in an attachment. I have tried the following combinations and nothing seem to work:

<img src="'servlet/servlet.FileDownload?file='{productItem.product.attachmentId}"/>
<img src="/servlet/servlet.FileDownload?file={productItem.product.attachmentId}"/>
<img src=\{imageDownload}{productItem.product.attachmentId}/> <!--(imageDownload = '/servlet/servlet.FileDownload?file=';)-->
<img src="'https://ccdev3-abinbev-ei-crm.cs105.force.com/MyABIB2BCommunity/servlet/servlet.FileDownload?file='+{productItem.product.attachmentId}"/>
<img src="'https://ccdev3-abinbev-ei-crm.cs105.force.com/MyABIB2BCommunity/servlet/servlet.FileDownload?file='{productItem.product.attachmentId}"/>
<img src="https://ccdev3-abinbev-ei-crm.cs105.force.com/MyABIB2BCommunity/servlet/servlet.FileDownload?file={productItem.product.attachmentId}"/>```

Output:
https://i.sstatic.net/6q8kt.png

Solution

  • I have managed to fix the issue by changing the wrapper from an Id to a String with hard coded value: Basically my wrapper now looks like attachmentId: "https://ccdev3-abinbev-ei-crm.cs105.force.com/MyABIB2BCommunity/servlet/servlet.FileDownload?file=00P1w000003eSStEAM"

    and in LWC HTML I simply use: