2

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? Below is the stack trace of the error i get Error: Received exception event aura:systemError from server↵ at T.Pg (https://ef--dupcheck.lightning.force.com/auraFW/javascript/HbiHlokP8ngGntuPI-9lcw/aura_prod.js:512:370)↵ at Object.onXHRReceived (https://ef--dupcheck.lightning.force.com/components/instrumentation/beacon.js:6:206)↵ at Object.FH.dk (https://ef--dupcheck.lightning.force.com/auraFW/javascript/HbiHlokP8ngGntuPI-9lcw/aura_prod.js:220:255)↵ at oM.Co (https://ef--dupcheck.lightning.force.com/auraFW/javascript/HbiHlokP8ngGntuPI-9lcw/aura_prod.js:873:391)↵ at Object.FH.dk (https://ef--dupcheck.lightning.force.com/auraFW/javascript/HbiHlokP8ngGntuPI-9lcw/aura_prod.js:220:255)↵ at chrome-extension://alkcnclapbnefkodhbkpifdkceldogka/dist/gatherer.js:1:44900↵ at Object.FH.dk (https://ef--dupcheck.lightning.force.com/auraFW/javascript/HbiHlokP8ngGntuPI-9lcw/aura_prod.js:220:255)↵ at FH.start (https://ef--dupcheck.lightning.force.com/auraFW/javascript/HbiHlokP8ngGntuPI-9lcw/aura_prod.js:219:313)↵ at XMLHttpRequest.e (https://ef--dupcheck.lightning.force.com/auraFW/javascript/HbiHlokP8ngGntuPI-9lcw/aura_prod.js:506:103)↵ at XMLHttpRequest.b (https://ef--dupcheck.lightning.force.com/auraFW/javascript/HbiHlokP8ngGntuPI-9lcw/aura_prod.js:820:83)"

3
  • 1
    when you say it Fails - can you further expand on that? what is the error message? any debug info from your browsers dev tools? ContentVersion Size Limits – glls Jul 25 '17 at 18:35
  • There's a limit on the size of a request payload in Lightning that's about 1MB (I haven't found the exact size yet). You'll probably need to devise a way to upload this in parts. – sfdcfox Jul 25 '17 at 18:42
  • I do not see it, however, @sfdcfox is right, at the moment, there seems to be a 1MB limit on file uploads in lightning I found this in the developer blogs unless you use visualforce, which will considerable increase the limit – glls Jul 25 '17 at 19:05
3

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.

2
  • nice! I was looking for that. thx for sharing the link – glls Jul 26 '17 at 2:51
  • @Daniel Ballinger Thanks for the detailed explanation. I will work on this further and update. – Anee Jul 26 '17 at 2:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.