[SalesForce] File uploader to SE from within Lightning Component

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.

Best Answer

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.