2

I want to make a "custom file upload" LWC component as I am in need to build a specific design for an upload process.

There are a few things I am not sure about.

  1. What would be the maximum size of a blob that I can pass from the JS side to APEX.
  2. Is using a @wire method to get to APEX the best approach here? If not what would be a better way?
  3. Is it possible to chunk the blob, pass one chunk at a time and store it in the same ContentVersion? Example: I will chunk the file blob depending on the size limit(heap size limit and what I can pass from JS to APEX). Then I want to pass one chunk and save it in a ContentVersion. Then pass the next chunk, have APEX pull the ContentVersion, append the new blob to what is already in the ContentVersion and save. Then keep doing the same thing until all chunks have been passed to SF and appended to each other. Is this going to create a new version every time that I try to save or can I re-save in the same version?

I tried to explain my concerns to the best of my ability. Please if anything doesn't make sense let me know and I will try to elaborate.

3

What would be the maximum size of a blob that I can pass from the JS side to APEX.

It was documented to be 1 mb from lightning component to Apex in 1 transaction. However I do not find that documentation now. Also in my testing it started throwing error after about 716kb

Is using a @wire method to get to APEX the best approach here? If not what would be a better way?

Imperative apex is better suited for file upload because To use @wire to call an Apex method, you must set cacheable=true. and so can only get data

Is it possible to chunk the blob, pass one chunk at a time and store it in the same ContentVersion? Example: I will chunk the file blob depending on the size limit(heap size limit and what I can pass from JS to APEX). Then I want to pass one chunk and save it in a ContentVersion. Then pass the next chunk, have APEX pull the ContentVersion, append the new blob to what is already in the ContentVersion and save. Then keep doing the same thing until all chunks have been passed to SF and appended to each other. Is this going to create a new version every time that I try to save or can I re-save in the same version?

Using chunking you can upload around 4mb of file in same content version/document. If its more than 4mb, it will throw error and so is better to have check < 4mb of total size.


The limitations are enforced by salesforce for custom components (not standard) as stated in documentation:

enter image description here

| improve this answer | |
  • Thank you. How can <lightning-file-upload> allow for files up to 2 GB then? It's also using ContentVersion and ContentDocument right? Is there a way for me to reach that file size? – Arthlete Jun 5 at 6:30
  • 1
    added in answer the reason – salesforce-sas Jun 5 at 6:39
  • The "about 716kb" is because the file must be base64-encoded. This would align with the 1MB limit that you had in mind, so this sounds right. – sfdcfox Jun 5 at 11:58
  • 2
    @Arthlete The 2GB thing happens because it uses a REST API designed to handle the 2GB limit. If you go through Apex, you're instead limited. – sfdcfox Jun 5 at 11:59
  • 1
    I might try to do this through the REST API and let you know how it goes. – Arthlete Jun 6 at 0:37

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.