+ Start a Discussion
sfdctrrsfdctrr 

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.

 

 

SFDC.

sfdctrrsfdctrr

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}" 
                id="newAttach" 
                styleclass="newAttach" 
                contentType="{!newAttach.ContentType}" 
                filename="{!newAttach.Name}" 
                fileSize="{!newAttach.BodyLength}" />
<apex:CommandButton action="{!uploadAction1}" value="Upload Photo"/>

   </apex:form>

</apex:componentBody>
</apex:component>

 

 

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';
//uploadAction();
}
 public PageReference uploadAction1(){
        
        
        PageReference thePage = new PageReference( '/'+ parentId );
        thePage.setRedirect( true );
        if(true){
        
            return ( this.saveCurrentPicture() ) ? thePage : null;
        }
        else{
         
            this.newAttach = new Attachment();
            return null;
        }
    }   
 public Boolean saveCurrentPicture(){
    
        //Savepoint sp = Database.setSavepoint();
        try{
            
          

            this.newAttach.parentId = '0069000000639Vi';
               

            this.newAttach.name = 'Contact Picture';
              


            insert this.newAttach;
              

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

 Thanks.

sfdctrrsfdctrr

Can anyone answer to this question or any suggestions.