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
MarrisMarris 

How to get attachment size?

Hi,

        

         When i run this below code for 1 mb attachment file it runs perfectly, but when i try to increase my attachment size to 2 to 5 mb i got an file not found error  and redirected to some page.Can any plz help me? 

 

public with sharing class AttachmentUploadController { 

public string attchname {get; set;} 

public blob attchfile {get; set;} 

public integer attchsize {get; set;} 

public string attchdescription {get; set;} 

public boolean getIsSaved() {return isSaved;}

 

 

 

public void upload()

{     

Attachment attch = new Attachment();     

if(attchName == null || attchfile == null || attchName == '' )

{         

attch.addError('Select a file to upload.');       

}

else {         

if (attchfile.size() > 1048576) {             

system.debug('The attached filesize is: ' +attchsize );             

system.debug('The attachmentsize is ' +attchfile.size() );             

string CaseId = ApexPages.currentPage().getParameters().get('cId');             

attch.ParentId = CaseId;             

attch.Name = attchName;             

attch.Body = attchfile;             

attch.Description = attchdescription;             

insert attch;             

isSaved = true;             

attch.body = null;             

attchfile = null;                       

} else

{             

system.debug('The attached filesize is: ' +attchsize );             

system.debug('The attachmentsize is ' +attchfile.size() );             

attch.addError('File size should be less than 5 MB');                        

}     

}

 

Thanks in advance.....

apaiapai

Attachment.BodyLength

 

Check this ...

MarrisMarris

Sorry apai, still i forwarded to some other page if i upload file greater than 1 mb but thanks for ur reply

 

Can anyone provide me a solution.

apaiapai

are you using custom VF page, where an attachment is uploaded ?

MarrisMarris

Hi apai, I used a VF page in customer portal which is using this controller to upload a file in case sobject