+ Start a Discussion

How to define a component which should be capable of upload photo and display

Hi Folks,

 I have a requirement such that I need to define a component whcih is capable of upload photo and display.


for e.g. When user clicks on link "Add Photo" a popup window will popup to upload a file once flie is uploaded it should  display the image.


For this i need to define a component so that can be used any VF pages(As a component anybosy can use this).


Few things observed:

When user logged into salesforce, once click on his profile there is option to Add photo, we are looking for same functionality.


Thanks in advance, Any help Appreciated.





Hi Folks, Any ideas!!! I have written a piece of code but the problem what i'm facing is I caouldn't able to call custom action from component.


In the below code i couldn't able to call the custom action "uploadAction1()"  from the component. Pls let me know if anything wrong.


Component Code:


<apex:component controller="PhotoUpload" allowDML="true" >

<apex:componentBody >
<apex:form >

<!--<apex:actionRegion >-->
<apex:inputFile value="{!newAttach.Body}" 
                fileSize="{!newAttach.BodyLength}" />
<apex:CommandButton action="{!uploadAction1}" value="Upload Photo"/>





Controller Code:


public class PhotoUpload{

public Attachment   newAttach           { set; get; }
private String      parentId            { set; get; }
private Set<String> imagesTypes         = new Set<String> {'image/jpeg', 'image/pjpeg', 'image/png', 'image/x-png', 'image/gif'};
   private final String  ERROR_IMG_TYPE    = 'The image must be .jpg, .gif or .png';   
public String       error               { set; get; }

public PhotoUpload(){
this.newAttach = new Attachment();

 this.parentId       = '0069000000639Vi';
 public PageReference uploadAction1(){
        PageReference thePage = new PageReference( '/'+ parentId );
        thePage.setRedirect( true );
            return ( this.saveCurrentPicture() ) ? thePage : null;
            this.newAttach = new Attachment();
            return null;
 public Boolean saveCurrentPicture(){
        //Savepoint sp = Database.setSavepoint();

            this.newAttach.parentId = '0069000000639Vi';

            this.newAttach.name = 'Contact Picture';

            insert this.newAttach;

            return true;
        catch( Exception e ){
           // this.error += ERROR_NO_SAVE+'<br/>';
            //Database.rollback( sp );
            return false;



Can anyone answer to this question or any suggestions.