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
Tanya ShahTanya Shah 

Image showing null in response

I'm trying to show image through API . But the image doesnt show up on page . With debugging it is showing image as null . Am i missing something or doing wrong ? Please help.
Thank you !

Apex
 
public class RestImage {

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

    http p =new http();
    httprequest req= new httprequest();
    req.setEndpoint('https://s3.amazonaws.com/soap');
    req.setMethod('GET');
    req.setTimeout(11000);
    
    httpresponse res= p.send(req);
    code=res.getStatus();
    values=res.getBody();
    image=res.getBodyAsBlob();
   // image=EncodingUtil.base64encode(res.getBodyAsBlob());

    System.debug(res.getBody());
    System.debug(image);
  
   }
 }
Visualforce
 
<apex:page controller="RestImage" action="{!myConnection}">
  {!code}{!values}
  <apex:form > {!image}</apex:form>
  
  <apex:image value="data:image/gif;base64,{!image}" />

</apex:page>


 
BalajiRanganathanBalajiRanganathan
1) Verify your endpoint. i think it is not complete. visit the endpoint directly in the browser. it should show the image.
2) if you have not added the domain to remote site settings add it.
Tanya ShahTanya Shah
Yes, my endpoint is not complete . Could you please help me out to get this as i'm new to this . Want to retrive image through API from Amazon . I'm using AWS toolkit .
BalajiRanganathanBalajiRanganathan
If the Image has public/read access, i think you can directly use it in the VF using apex image. otherwise you need to install AWS Toolkit for Force.com.
https://developer.salesforce.com/page/Amazon_Toolkit
 
Tanya ShahTanya Shah
I've already installed toolkit for this. I want to show images in thumbnail format where i get images through API .The image is in string format and thus want to have it in Blob . But the endpoint here is not making me go ahead. Would be extremely helpful if you can please guide me .