Server Bug Fix: LWC: Maximum Blob Size From JS To APEX

Original Source Link

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.

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

Tagged : / / / /

Leave a Reply

Your email address will not be published. Required fields are marked *