function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
MohaMoha 

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;
}

Puja_mfsiPuja_mfsi

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.

 

Avidev9Avidev9
I would like you to check the Standard Object permissions as well!
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
MohaMoha

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

Avidev9Avidev9
I dont think you need another page. You just have to place the code in a right way.
All the suggestion given were to debug incase the images not appear
MohaMoha
i'm trying to debug but it's not debuging i don't know why, mmm do you see any error in that code ? thanks for the help
Avidev9Avidev9
How about printing url in the page and compare the same with the original version from document ?
MohaMoha
when i print the url, it renders the name of the Document in the portalSite, and it renders the Image on a normal Tab in the Admin Side
Kiran  KurellaKiran Kurella

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.

 

 

 

 

Avidev9Avidev9
can you post the url here?
MohaMoha

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 ?

 

<apex:iframe src="{!HTML}"/>

public string getHTML()
    {    
        document= 'Document';
       List<Document> lstDocument = [Select Id,Name,LastModifiedById from Document where Name = :Document  limit 1];
        string strDocUrl = 'https://'+ApexPages.currentPage().getHeaders().get('Host')+ '/servlet/servlet.FileDownload?file='+lstDocument[0].Id;
        return strDocUrl;      
    }

 


 

 

 

MohaMoha
Hello Again, the problem is in this part of the url : https://'+ApexPages.currentPage().getHeaders().get('Host')
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)