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
bblaybblay 

Limit File Upload Size??

Is it possible to limit the file attachment size on a custom object? 

 

I believe I read that the current Salesforce limit is either 5 or 10mb but I'd like to limit it to only 2mb per attachment as I have users that will be uploading multiple pictures and I don't want my file storage usage limits to be exceeded as some people are capturing images on their 13 megapixel cameras at 6mb a picture. I want to be able to limit these types of people uploading images to just the 2mb.

 

I'm currently working through a developer edition account and my file storage limit is 20mb, but in the future I'll be upgrading but will be having hundreds of users uploading images and cannot afford to take up storage space. As also each user is displayed on a search page I created with one of their images they've uploaded and I need to cut down on the page's loading time too.

 

Also, is it possible to limit the number of attachments that can be uploaded, to say 7 attachments?

 

Thanks for any ideas you might be able to share!!  

gv007gv007

At the time of file upload you can find the size of the blob then put a condition if the size is grater then salesforce display a message to user.i.e the maximum size he can upload.

bblaybblay

Thanks Gopi! Do you know where there might be some examples or documentation for this to get me started?

 

Below is just the apex for the attachments that users upload. 

 

 

 

public class imageUpload  
{  
    public Id recId  
    {    get;set;    }  
      
    public imageUpload(ApexPages.StandardController ctlr)  
    {  
       recId = ctlr.getRecord().Id;       
    }  
      
    public string fileName   
    {    get;set;    }  
      
    public Blob fileBody   
    {    get;set;    }  
    
    public PageReference UploadFile()  
    {  
        PageReference pr;  
        if(fileBody != null && fileName != null)  
        {  
          Attachment myAttachment  = new Attachment();  
          myAttachment.Body = fileBody;  
          myAttachment.Name = fileName;  
          myAttachment.ParentId = recId;  
          insert myAttachment;  
             PageReference page = ApexPages.currentPage();
             page.setRedirect(true);
             return page;              
        }  
        return null; 
    }          
}

 

 

gv007gv007

There is an example in uploding documents to AWS see that example it will work

 

you need use an VF page to handle the front end

 

 <apex:form  enctype="multipart/form-data">

<apex:inputfile > Tag use following tag.If i got a chance i will post some sample code.

bblaybblay

 

 

I'm trying to accomplish three things with this but only need to figure out #2 still:

 

1) Upload an image attachment. (Successful)

 

2) Limit the file size attachment to less than 2 MB (Still need help)

 

3) Allow users to only upload no more than 7 images, otherwise they are deleted (Successful)

 

I think I have the right idea here but am looking for some suggestions and how to make this actually work and limit images to 2MB or less. Thanks!

 

 

public class imageUpload  
{  

    public Id recId {get;set;}  
      
    public imageUpload(ApexPages.StandardController ctlr)  
    {  
       recId = ctlr.getRecord().Id;       
    }  
      
    public string fileName {get;set;}  
      
    public Blob fileBody {get;set;}  
    
    private integer fileSize;
    
    public Blob getFileBody()
    {
        return this.fileBody;
    }
    
    public void setFileBody(Blob fileBody)
    {
        this.fileBody = fileBody;
        setFileSize(this.fileBody.size());
    }

    public Integer getFileSize()
    {
        return this.fileSize;
    }

    public void setFileSize(Integer fileSize)
    {
        this.fileSize = fileSize;
    }
    
    
      
                                                  
    public PageReference UploadFile()  
    {  
        PageReference pr;  
        if(fileBody != null && fileName != null)  
        {  
        
          Attachment myAttachment  = new Attachment();  
          myAttachment.Body = fileBody;  
          myAttachment.Name = fileName;  
          myAttachment.ParentId = recId;  
          insert myAttachment;  
  
          Member__c m = [select id from Member__c WHERE ID=:System.currentPageReference().getParameters().get('id')];
          List<Attachment> a = [select id from attachment where parentid = :m.id];
 
 
          if(a.size() > 7){
            delete a;         
          }                                   
                   
          PageReference page = ApexPages.currentPage();
          page.setRedirect(true);
          return page;    
        }  
        return null; 
    }    

  
}

 

 

 

Kumar Saurav 10Kumar Saurav 10
"Are you Looking for large file Storage in Salesforce..?
We got a solution for you…!

Here you may be interested in knowing about appexchange native app Cloud Drop which is having this feature.

For more details check:
http://www.clouddrop.io

Check Out the following URL for application:
https://appexchange.salesforce.com/listingDetail?listingId=a0N30000003IzEDEA0"