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
Sameer TyagiSameer Tyagi 

HI, I have Html content in a string, Html content contains images and text. Unable to see images of html content on vf page.

Hi, 

1) I am saving incoming Email body content in html attachment.  
with this code
Attachment attach = new Attachment(Name = newEmail.Name + '.html', Body = Blob.valueOf(email.htmlBody),
                        ContentType = '.html', ParentId = newEmail.id); 
                insert attach;

2) now I am using the body of attachment like this ..

string attachBody=attach.Body.toString();

3)  I am using string 'attachBody' on vf page like this
<apex:outputText escape="false" value="{!attachBody}">

Now issue is that..  I am unable to see few images on vf page. 

As I see in debug logs, I found 

1. if  string 'attachBody'  contains this <img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAacAAAD7CAIAAABBtsz  ... that is visible to me on vf page.
2. if  string 'attachbody' contains this <img src="cid:3442459202_25472939  ...  I see broken image 

Your help would be appricaited.  

Sameer Tyagi


 

 

Damien Phillippi033905702927186443Damien Phillippi033905702927186443
The first issue is that you are specifically telling Salesforce to display the image as a String by using an apex:outputText variable.  You MIGHT be able to do it if you used an apex:outputField or apex:image.  I haven't tried either of those and I have no idea if they will actually work, but it might be a better approach than trying to display them as Text.  Alternatively, it might be worth trying to simply bind the String variable directly onto the page without having any sort of apex component wrapping it.  I would try all 3 of my below ideas and let me know if any work.

<pre>
<apex:outputField value="{!attach.Body}" />
</pre>
<pre>
<apex:image value="{!attach.Body}" />
</pre>
<pre>
{!attachBody}
</pre>
Sameer TyagiSameer Tyagi
HI Damien Phillippi,

1 . outputfield does not support blob
2. Content cannot be displayed: core.filemanager.ByteBlobValue cannot be cast to java.lang.String
getting this error If I use <apex:image value="{!attach.Body}" />

I am able to see image . if  string 'attachBody'  contains this <img src="data:image/pngbase64,iVBORw0KGgoAAAANSUhEUgAAAacAAAD7CAIAAABBtsz  ...

and NOT able to see image on vf page if  string 'attachbody' contains this <img src="cid:3442459202_25472939
string Attachbody contains HTML body(string and Images with HTML tags)

I am using outputtext with escape = "false" which hides HTML tags
Damien Phillippi033905702927186443Damien Phillippi033905702927186443
Ahhh ok.  Well sorry I don't really have much more useful for you.