Skip to main content

I am aiming to take a file a user attaches through an Lightning Component and create a document object containing the data. 

So far I have overcome the request size limits by chunking the data being uploaded into 1MB chunks. When the Apex Aura method receives these chunks of data it will either create a new document (if it is the first chunk), or will retrieve the existing document and add the new chunk to the end.

Data is received Base64 encoded, and then decoded server-side.

As the document data is stored as a Blob, the original file contents will be read as a String, and then appended with the chunk received. The new contents are then converted back into a Blob to be stored within the ContentVersion object.

The problem I'm having is that strings in Apex have a maximum length of 6,000,000 or so. Whenever the file size exceeds 6MB, this limit is hit during the concatenation, and will cause the file upload to halt.

I have attempted to avoid this limit by converting the Blob to a String only when necessary for the concatenation (as suggested here https://developer.salesforce.com/forums/?id=906F00000008w9hIAA) but this hasn't worked. I'm guessing it was patched because it's still technically allocating a string larger then the limit.

Code's really simple when appending so far:

 

ContentVersion originalDocument = [SELECT Id, VersionData FROM ContentVersion WHERE Id =: <existing_file_id> LIMIT 1];

Blob originalData = originalDocument.VersionData;

Blob appendedData = EncodingUtil.base64Decode(<base_64_data_input>);

Blob newData = Blob.valueOf(originalData.toString() + appendedData.toString());

originalDocument.VersionData = newData;

2 个回答
  1. 1月29日 08:08

    Can you please add a link to where this "Salesforce Apex File Upload Limits and Chunking" is documented?

0/9000