+ Start a Discussion
Ram ChaturvediRam Chaturvedi 

How can we store a picture in a apex variable ?

I am fetching a picture from an object and want to store in a apex variable , in which data type we can store that image and how ?
MithunPMithunP
Hi Ram,

You can use BLOB datatype.

Best Regards,
Mithun.
Tony TannousTony Tannous
Hello,

it depend how you are fetching the picture, you can store it in a blob variable, or in a string variable and then use EncodingUtil.base64Decode

Good Luck.

 
Ram ChaturvediRam Chaturvedi
Thanks Tony  , i also want to print that img on vf page , so how can we do that . 
 
Tony TannousTony Tannous
In your Class add this  Public blob imageObj {get;set;}

and you need to set the value imageObj with the data selected from your object.

now In your VF page put this 
<apex:image value="{!imageObj}" />

Regards
 
Chidambar ReddyChidambar Reddy
Hi, You can use Text Area Rich to store your images

and you can show them on VF page as well
rajesh reddy 3rajesh reddy 3
Bro can you send your mail ID or Phone Number  if possible
Ram ChaturvediRam Chaturvedi
Thanks Tony ,
i am doing like this 
 blob img =  EncodingUtil.base64Decode(students[0].photo__c);
 // error System.StringException: Unrecognized base64 character: < 


<apex:image value="{!record.img}"/>

how can i make it correct ?
Tony TannousTony Tannous
in case you have a salesforce object name student__c , with a field name photo__c

You can do the below in the class apex 

Public student__c studentObj {get;set;}

in the constructor select the student__c record related and set it to studentObj 

and in you VF page just put <apex:outputField value="{!studentObj .PhotoUser__c}"/>

And it will work



 
Ram ChaturvediRam Chaturvedi
Thanks Tony . But i am working with wrapper class . Because i want to create datatable for displaying data from different Object .

 wrps = new list<wrap>();
        wrap w1 = new wrap();
        w1.snm = students[0].name ;
        w1.fnm = 'The Great Faculty khusuboo';
        w1.img =  EncodingUtil.base64Decode(students[0].photo__c);
        wrps.add(w1); 
                    
    }
    
    class wrap{
    
        public string snm{set; get;}
        public string fnm{set; get;}
        public blob img{set; get;}    
    
    }

vf code :
<apex:column headerValue="student Photo ">
           <apex:image value="{!record.img}"/> 
</apex:column>
Tony TannousTony Tannous
Do the below modification to you wrapper

class wrap
{
        public string snm{set; get;}
        public string fnm{set; get;}
        public Sobject sfdcObject{set; get;}    
  }


 wrps = new list<wrap>();
        wrap w1 = new wrap();
        w1.snm = students[0].name ;
        w1.fnm = 'The Great Faculty khusuboo';
        w1.sfdcObject=  students[0];
        wrps.add(w1); 


<apex:column headerValue="student Photo ">
<apex:outputField value="{!record.sfdcObject['photo__c']}"/>
</apex:column>

Good Luck


 
Ram ChaturvediRam Chaturvedi
Thank You soo much Tony Its working now .

:-)

and can you give any link where i can study more about  "
EncodingUtil.base64Decode
" and if we want to do this by using <apex:image> then how can we do ?