Anee
Anee

Reputation: 483

Size limit on ContentVersion object in Salesforce

I was trying to create and insert a ContentVersion object in Salesforce lightning(for file upload) using the following code:

        ContentVersion v = new ContentVersion();
        v.versionData = EncodingUtil.base64Decode(content);
        v.title = fileName;
        v.pathOnClient = fileName;
        insert v;

This works fine for smaller files. But when i try loading a file which is just 750KB the above operation fails(actual allowed size could be still less). Is there any limit on the size if the files that could be uploaded using the above code?

Upvotes: 1

Views: 4950

Answers (1)

Daniel Ballinger
Daniel Ballinger

Reputation: 13537

As per the similar question from the Salesforce StackExchange.


From Base Lightning Components Considerations:

When working with type="file", you must provide your own server-side logic for uploading files to Salesforce. [...] Uploading files using this component is subject to regular Apex controller limits, which is 1 MB. To accommodate file size increase due to base64 encoding, we recommend that you set the maximum file size to 750 KB. You must implement chunking for file size larger than 1 MB. Files uploaded via chunking are subject to a size limit of 4 MB.

The Base64 is pushing the file size past the Maximum HTTP POST form size—the size of all keys and values in the form limit of 1 MB. Or at least this seems like the applicable limit here.

Instead you will need to go with either an embed Visualforce page as used in How to Build a Lightning File Uploader Component. This gets you up to the Maximum file size for a file uploaded using a Visualforce page limit of 10 MB. Just remember to keep the file processing to a minimum before the heap size limit catches up with you.

Upvotes: 0

Related Questions