[SalesForce] How to show attachment images to Guest User in VisualForce page under Sites

I want to display Attachment images related to the Product2 object in a VisualForce page under Site to Guest User.

I have prepared the image url like below and have set it in an img tag.
'/servlet/servlet.FileDownload?file=' + attachment.id

When I open the VF page by logging into SalesForce, I'm able to see the images. But under Sites when I view the VF page as a public url, the images are not shown.

Kindly tell me which permission settings should be configured to show the attachment images to Guest Users.

Best Answer

Okay, I have resolved this issue as I was preparing a wrong Image Url for the attachment.

My Site url was 'https://sandbox6-qbscompanies.cs23.force.com/registration', and the image url was getting resolved to 'https://sandbox6-qbscompanies.cs23.force.com' + '/servlet/servlet.FileDownload?file=' + attachment.id.

Thus I set the image url like '/registration/servlet/servlet.FileDownload?file=' + attachment.id. Then it worked correctly on public site.

Related Topic