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
XexiXexi 

File Path missing in IMPUTFILE

We have a Visualforce page that is used to upload multiple images. The problem is that to validate, if it shows any errors, the page loses all of the images path.

I understand that safety is a value that is not retained. Anyone know a way I do not miss the path?

Thanks
AmitSahuAmitSahu
When you are using input file tag , you cannot rerender the page. If you are using refresh mechanism it wont work.
Ranu JainRanu Jain

Can you please provide your code?

XexiXexi

Hi,

This is my code VF:

<apex:page controller="GRP_MultiImagenes" action="{!constructor}">
  <apex:form >
  <apex:pageMessages id="errors" />
    
    <apex:pageBlock title="LOAD IMAGES" mode="edit">    
     
      <apex:repeat value="{!relatedListFile}" var="rel">
        <table width="100%" border="0" cellpadding="0" cellspacing="0">
          <tr>
            <td>&nbsp;</td><td colspan="3"><apex:outputLabel value=" Imagen:"/></td>
          </tr>
          <tr>
            <td>&nbsp;</td><td width="300"><apex:inputFile value="{!rel.file}" filename="{!rel.name}" fileSize="{!rel.size}"/></td>
            <td width="300"><apex:outputLabel for="postFileId" value="Etiqueta : "/><apex:inputtext value="{!rel.name}" /></td>
          </tr>
        </table>
        <br />
      </apex:repeat>
      
      <table width="100%" border="0" cellpadding="0" cellspacing="0">
        <tr>
          <td>&nbsp;</td>
          <td width="350"><apex:commandlink value="Show 3 rows more" action="{!addMore}"/></td>
          <td>
            <apex:commandButton value="Save" action="{!syncFilesystemDoc}"/>
            <apex:commandbutton value="Cancel" action="{!Cancel}"/>
          </td>
        </tr>
      </table>
 
    </apex:pageBlock>

    <apex:pageBlock >
      <table width="100%" border="0" cellpadding="0" cellspacing="0">
          <apex:outputPanel id="uploadObjectRender" >
             <apex:actionstatus id="statusForUploadObject">
               <apex:facet name="start">
                 <span style="font-weight:bold; color: red; background-color:white;">&nbsp;&nbsp;&nbsp;Conectando a Amazon S3..........&nbsp;&nbsp;&nbsp;</span>
               </apex:facet>
               <apex:facet name="stop">
                 <apex:outputPanel rendered="{!(AND(!ISNULL(uploadObjectErrorMsg),uploadObjectErrorMsg!='Success'))}" style="font-weight:bold; color: red; background-color:white;">
                   &nbsp;&nbsp;&nbsp;ERROR: {!uploadObjectErrorMsg}
                 </apex:outputPanel>
               </apex:facet>
             </apex:actionstatus>
                
             <apex:outputPanel rendered="{!(AND(!ISNULL(uploadObjectErrorMsg),uploadObjectErrorMsg=='Success'))}" style="font-weight:bold; color:green; background-color:white;">&nbsp;&nbsp;&nbsp;Imagen cargada. Si desea puede cargar otra.
             </apex:outputPanel>
         </apex:outputPanel>
       </table>
     </apex:pageBlock>
  </apex:form>
</apex:page>

 
This is APEX code:

public class GRP_MultiImagenes{

  //Variables fichero
    public String uploadObjectErrorMsg {get;set;}
    public String deleteObjectErrorMsg {get;set;}
    public String listBucketErrorMsg {get;set;}
    
  //Variables S3
     public String bucketToUploadObject;
     public String accessTypeSelected;
     public String OwnerId {get;set;}
 
  //Variables Force
     public Id sCaId {get; set;}
     
     public List<RelatedListWrapper> relatedListFile =new List<RelatedListWrapper>();
   
     public List<RelatedListWrapper> getrelatedListFile(){   
       if(relatedListFile.size() == 0){
         relatedListFile = new List<RelatedListWrapper>();
         relatedListFile.add(new RelatedListWrapper(null, null));
         relatedListFile.add(new RelatedListWrapper(null, null));
         relatedListFile.add(new RelatedListWrapper(null, null));
       }
      
      return relatedListFile ;
    }
    
    public class RelatedListWrapper{
        public String  Name {get;set;}
        public Integer Size {get;set;}
        public Blob    File {get;set;}
        
        public RelatedListWrapper(String s, Integer si,Integer i, Boolean b, Blob Bl){
        system.debug('*** RelatedListWrapper');
            this.Name = s;
            this.Size = si;
            this.File = bl;
        }
    }
 
  //Constructor
  public GRP_MultiImagenes(){}
  public PageReference constructor(){
       sCaId = ApexPages.currentPage().getParameters().get('Campaign');
      return null;
  }
 
  public pageReference syncFilesystemDoc(){
     try{
       system.debug('***** SAVE *****');
       List<GRP_MultiImagenes__c> toInsertMI = new List<GRP_MultiImagenes__c>();
       string IdS3;
       Boolean putObjResult;
       Boolean vError=false;      
       
       for (RelatedListWrapper relatedListFile : relatedListFile){
         if(relatedListFile.file != null){
           if(relatedListFile.file != null && relatedListFile.name == '') vError=true;
         }
       }
      

       if(vError==true){

uploadObjectErrorMsg = 'ERROR';
         return null;

       }
      
       for (RelatedListWrapper relatedListFile : relatedListFile) {

           if (relatedListFile.name!=''){

               Datetime now = Datetime.now();
               IdS3 = relatedListFile.name;
             
             //Recogemos la ruta y lo transformamos a base64.
               String docBody = EncodingUtil.base64Encode(relatedListFile.file);

             //Si la respuesta es optima añadimos el registro a Force.
                 toInsertMi.add(new GRP_MultiImagenes__c(Id_Amazon__c=IdS3,campaign__c=scaId,name=relatedListFile.name,orden__c=relatedListFile.orden,FileSize__c=relatedListFile.size,Imagen_principal__c=relatedListFile.principal));
           }
       }
       //Creo los registros en Force. Los q únicamente se han creado en
         Insert toInsertMI;
       // Envía al usuario al detalle de la página del sobject
         return new PageReference('/' + sCaId);
     }catch(System.CalloutException callout){
       System.debug('CALLOUT EXCEPTION: ' + callout);
       uploadObjectErrorMsg =    callout.getMessage();
       return null;
     }catch(Exception ex){
       System.debug('EXCEPTION: ' + ex);
       uploadObjectErrorMsg =  ex.getMessage();
       return null;
     }
  }
 
  public pagereference Cancel(){
     return new PageReference('/' + sCaId);
  }
  public void addMore(){
        // append NUM_ATTACHMENTS_TO_ADD to the new attachments list
        integer ord = relatedListFile.size()+1;
        for (Integer idx=0; idx<3; idx++){
            relatedListFile.add(new RelatedListWrapper(null, null,ord+idx,false,null));
        }
    }

AmitSahuAmitSahu
http://bobbuzzard.blogspot.com/2011/01/uploading-multiple-attachments-via.html

Use the above link and you can make the changes . It works great . Good one from Bob....