You need to sign in to do that
Don't have an account?
Dynamic reference to Static Resource in Managed Package
I am developing an application which includes a configuration object that allows a user to specify an image they would like displayed on a VF page. The user must type in the filename of the image and include the image in an existing Static Resource zip file. The visual VF page then retrieves the correct image as below:
<apex:image url="{!URLFOR($Resource.Logos, Logo)}"/>
The Controller Extension has a method getLogo() which returns the appropriate filename.
This is all very nice, however it won't work in a Managed Package because the end user won't be able to update the SR zip file. It will be locked.
Does anybody have a workaround for this. Or an idea of how I might be able to achieve the same result differently?
Many thanks.
I found moving to Documents rather than Static Resources solved the problem. Now the user will be able to upload their own images as documents and the VF page will display the appropriate image. See code snippet from VisualForce page and Controller
I don't have the URL handy, but you can refer to a static resource via URL instead of using the $Resource syntax. Just inspect the URL to your resource and you'll see the structure. Strip out the random number in the middle. They can then enter the resource into your config and then you can construct a URL using it.
Keep in mind if the customer replaces their static resource content, it will take a while for it to be refreshed. The random number is updated each time they replace the static resource content. That new number forces the browser to update their images/css stored in that static resource. Since you'll be removing the number (you won't know the number), then it might take a bit more time for browsers to update the content.
Hope that helps!
Is there an easy way for a not particularly proficient Salesforce user to get the url for their recently updated static resource?
The "random number" is actually a timestamp. So you cannot safely hardcode the /resource/<timestamp>/<resourcename> into your code. The timestamp changes every time the resource is updated.
thanks