1
votes

I am using sites and wish to display an image in one of my pages. The image is a salesforce document. I have no troubles displaying static resources fine. I have set the permissions on the images to be externally available.

(just image related code..)

visualforce code:

<img src="{!Image}"/>

Controller code:

string Image { get; set; }

public string getImage() {


List<Product2> productImage = new List<Product2>();
productImage = [SELECT Image__c FROM Product2];

return productImage[0].Image__c;
}

On firebug inspection I have noticed it is getting the URL of the image fine but it can't display it. Any ideas?

2
If you look in the network part of Firebug is it managing to download the image? Could be security related perhaps? Or if it is downloading, maybe you need to specify some dimensions or similar? - Matt Lacey
Hi lacey, I am getting 404s so Im guessing its permissions related cheers - Jim
Sounds likely :) Good luck with it! - Matt Lacey
Try checking the “View Content on Portals” user permission - pbattisson

2 Answers

1
votes

There are a number of settings you probably need to enable first in order to do this. If you look at the link here then you should find the solution to your problem on the answer given.

Paul

1
votes

This is a tricky issue and requires including the resource ID in the URL. You can find out what the current resource ID is by placing an image from your static resource directly on a page and then using Firebug you can see what the actual URL is. For example, the following code displays an image from a resource file:

<apex:image url="{!URLFOR($Resource.Resources, 'MyImage.png')}">

Assuming this image displays properly, you will see in Firebug that the URL has a strange looking ID placed in it. If it doesn't display then follow the link provided by pbattisson for help with that. But if it does, then this is the actual URL you will need to use to display your images.

** Important - This resource ID will change when you change or otherwise re-save your static resource file and this new resource ID will then need to be applied somewhere, like in a URL_PREFIX value that you store in a custom setting, or directly in your custom Image__c field in Product2.