2

Am unable to display image which is there in external site .When am Displaying am getting like this

core.filemanager.FileBlobValue@4747ae4b 

here is my code

public class RestImage {

public blob image {get;set;}


public string code {get;set;}

public string values {get;set;}
public void myConnection(){

s= new SampleLead__c();
http p =new http();

httprequest req= new httprequest();

req.setEndpoint('http://1.cuzillion.com/bin/resource.cgi?sleep=10');
req.setMethod('GET');
req.setTimeout(11000);
httpresponse res= p.send(req);
code=res.getStatus();
values=res.getBody();
image=res.getBodyAsBlob();

}
}

her is my VisualForce page

<apex:page controller="RestImage" action="{!myConnection}">
  {!code}{!values}
  <apex:form >

  {!image}</apex:form>
</apex:page>

2 Answers 2

1

You can use inline the Data URI scheme:

Amend your Apex class with the following:

public blob image {get;set;}
...
public void myConnection(){
    ...
    image=EncodingUtil.base64encode(res.getBodyAsBlob());
}

Then update your Visualforce page:

<apex:image value="data:image/gif;base64,{!Image}" />

Interesting that you are stalling runtime using a sleepy URL ;-)

1

Why not just use a img tag setting the src to the external site?

<img src="http://1.cuzillion.com/bin/resource.cgi?sleep=10" />

I've noticed that you are trying to test something about loading performance, isn't? remember the browser load the img contents in an async way.

4
  • yes @marting then how can i show image ? is there any possible solution for that ,,instead of going for image tag ,how come i show those image
    – Vineeth
    Commented Dec 12, 2013 at 9:25
  • 1
    I think that I cant understand what are you trying to do. The result of VF is always HTML, the way to show an image in HTML is using <img>. Whay you can't use it tag? Commented Dec 12, 2013 at 9:32
  • A hybrid-solution would be to (1) use the img tag as suggested, but (2) load the image via jQuery (or any Javascript that'll work)instead of in the controller Commented Dec 12, 2013 at 17:18
  • or (3) write a @RemoteAction Apex Method that writes the URL for you (in case you wanted it automated using SF data) Commented Dec 12, 2013 at 17:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .