10

We've been looking for a way to inject large files (>5MB) in anyway from within a Lightning component. The Heap limits of APEX means we are limited to from passing the files to Apex then onward as need.

We've finally found that creating a HTML5 only form allow for the posting of a file to Amazon s3, once in s3 we can move it to were we actually need it.

Is there any reason to not continue to do this? We understand that this limits browser comparability that no more then Lightning already does. The below is a cut down sample of how we implement the uploader. There is no JavaScript involved in the actual upload.

<form aura:id="form" id="form" name="form" action="https://example.s3.amazonaws.com/" method="POST" enctype="multipart/form-data" novalidate="" 
      onsubmit="" onchange="" >

    <fieldset>
        <input type="hidden" id="MAX_FILE_SIZE" name="MAX_FILE_SIZE" value="300000000" />
        <input type="hidden" name="key" value="{!v.key+v.filename}" />
        <input type="hidden" id="x-amz-meta-tag" name="x-amz-meta-tag" value="1234567890adb"/>
 <input type="file" name="file" id="file" />        

            <button type="submit" onclick="">Upload Files</button>            
    </fieldset>

</form>

We'd like to know if this is how large file uploading should be handled or is the just a "bug" in locker services that wasn't closed as it doesn't involve JavaScript. Any input on how this can be done cleaner would be helpful.

PS. We have tested this with Large files (~250MB) without problem.

  • 1
    Do you mean that you're able to bypass the file size limit by uploading to S3 first and then copying that S3 file to your org via lightning component? – Gaurav Kheterpal Jul 2 '16 at 11:25
  • 1
    Every other uploader I've seen that works inside a Lighting component requires posting the file directly (or in chuncks) to an Apex controller. However, Apex has a relatively limited Memory limitation(6/12MB). By pushing the file directly to S3 we can then reload them back into what any service is needed. We are looking to push some files directly back in SFDC but other will probably be pushed to BOX and then access through Files Connect. – John Jul 2 '16 at 13:47
1

We had a similar requirement to upload large files to Salesforce and then upload them to external system via batch apex.

We tried couple of options:

  1. Like you mentioned, we tried to send data back to Salesforce, but we realized that even with Chunking, we won't be able to exceed 4.3MB limit due to payload size and the apex heap size etc.

  2. We tried to invoke Salesforce REST Service directly from Client side to invoke Files API (Ie, the content Object), but we got stuck with Session ID issue. We were advised not to generate session id from controller side and use it in lightning as they are served from different locations.

You mentioned you are connecting to Amazon S3, so in that case are you using any JS Library to authenticate and connect to S3?

http://docs.aws.amazon.com/AWSJavaScriptSDK/guide/browser-examples.html

If the above is the case, then JS file needs to be 100% locker service compatible (Ie, all the ES5 compatible).

I believe the best person to answer this question would be @Doug Chasman.

| improve this answer | |
  • I think we are talking past each other here. The big thing we did was to not utilize any JavaScript at all. As Locker service + CSP means no external posting. By utilize only HTML for and {link](docs.aws.amazon.com/AmazonS3/latest/API/sigv4-post-example.html) we completely bypass the Locker, what I'd like to know is if this is "condoned" behavior or is this basically utilize an exploit to the Locker. – John Jul 3 '16 at 14:04
  • Generally if the POST request is protected from CSRF, I personally don't see any issues with this approach. I am also interested in what this forum thinks. Sorry, don't have an authoritative answer. – Jag Jul 3 '16 at 21:01
  • Hi, I am not able to upload files with size more that 4 MB. Is it true that you cannot upload files with size more than 4.3MB ? is there any alternative to upload large files in contentVersion. refer to link for details : salesforce.stackexchange.com/questions/157024/… – Muzammil Bajaria Jan 23 '17 at 9:56
  • Hi @Jag , I also have similar requirement to upload large files using lightning component. I just want to know is it possible to upload a file greater than 4.3 MB using lightning component? – Muzammil Bajaria Jan 25 '17 at 7:26

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.