You need to sign in to do that
Don't have an account?
Moha
Cannot show Image from document on Site/Customer Portal
Hello i'm trying to show an image on site/Portal from Document i'm using the methode below, but unfortunately it doesn't show the Image, can anyone give me a help
VisualForce
<apex:image url="{!Logo}"/>
Controller :
public string getLogo()
{
List<Document> lstDocument = [Select Id,Name,LastModifiedById from Document where Name = 'LogoSite' limit 1];
string strOrgId = UserInfo.getOrganizationId();
string strDocUrl = 'https://'+ApexPages.currentPage().getHeaders().get('Host')+ '/servlet/servlet.ImageServer?id='+lstDocument[0].Id+'&oid=' + strOrgId;
return strDocUrl;
}
Hi,
First you need to give access of your page in site via the following step:
Develop -> site -> click on site name -> click on edit button of "Site Visualforce Pages" section.
and add your page .
If you have already add your page in site then You need to check in your document that the "Externally Available Image" checkbox in checked or not.
you need to select "Externally Available Image" checkbox.
Please let me know if your problem is persist.
if this solution is helpful please give me feedback by clicking the start Icon.
Develop -> site -> click on site name -> Public Access Settings ->>> Give the read permission.
well I will bet on "Externally Available Image" checkbox which puja_mfsi already pointed out
Hello, thanks for the reply for both of you, well i've already done this, but i need another solution which is, include the Image Directly from document to a SitePage, without creating an intermediaire VisualForce page then Include it in Site
i used this Code
public string getLogo()
{
logo = 'LogoSite';
List<Document> lstDocument = [Select Id,Name,LastModifiedById from Document where Name = :logo limit 1];
System.debug('document is:' +lstDocument );
strOrgId = UserInfo.getOrganizationId();
System.debug('orgId is:' +strOrgId);
string strDocUrl = 'https://'+ApexPages.currentPage().getHeaders().get('Host')+ '/servlet/servlet.ImageServer?id='+lstDocument[0].Id+'&oid=' + strOrgId;
System.debug('orgId is:' +strDocUrl);
return strDocUrl;
}
VF :
<apex:image url="{!Logo}"/>
the methode it returns the Url for Logo but when i include in <apex:image> it convers is to another Url which is the SiteUrl/DocumentName
but if i use
<apex:include pageName="PageLogo"/>
and the PageLogo contains : <apex:image url={!Logo}/> it returns the right Image
All the suggestion given were to debug incase the images not appear
Try replacing the following line
string strDocUrl = 'https://'+ApexPages.currentPage().getHeaders().get('Host')+ '/servlet/servlet.ImageServer?id='+lstDocument[0].Id+'&oid=' + strOrgId;
with
string strDocUrl = URL.getSalesforceBaseUrl().toExternalForm() + '/servlet/servlet.ImageServer?id=' + lstDocument[0].Id + '&oid=' + strOrgId;
If the problem still exists then create a new Public static resource and refer the image as follows
<apex:image value="{!$Resource.Logo}" />
or
<apex:image url="SITEURL/resource/Logo" />
Replace SITEURL with the actual site url.
Hello, thanks for the reply i tried your suggestions but unfortunately it's not working, all what it work is using VF as intermediate betwen Site and Document, and Ressource i don't want to use it because package is going to be managed, otherwise i'm working on using TextDocuments or HTML document with the same principe of Image, but now when i use an iframe it shows me the content in the ORg developement but in the SITE/PORTAL it shows me the Authentification is needed even if i set the document as searcheable and i've added the VF to the Site and added the VF to the profil, any suggestions ?
because it returns the SITEURL/servlet/servlet.ImageServer i've searched arround for away to change this url with https://c.eu2.content.force.com/servlet.... but i couldn't (this url is associated to the the Document path)