You need to sign in to do that
Don't have an account?
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.....
Attachment.BodyLength
Check this ...
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.
are you using custom VF page, where an attachment is uploaded ?
Hi apai, I used a VF page in customer portal which is using this controller to upload a file in case sobject