2

I had answered this question more than a year back where the file size was clearly documented to be 1 MB unless chunked to increase the limit to 4 MB, while using lightning:input and type="file".

However revisiting this for an implementation in LWC (assuming the limits would have remained same), I cannot find that same information on the documentation available anymore! While testing it seems the limit now is actually close to the payload limit of < 4MB (the actual file size that can be passed to the backend to be uploaded).

Does anyone know if there was an update on the component or there is a documentation available which speaks about the actual size limits while using the input component in aura or lwc?

3
  • Are you talking about uploading to Salesforce, or just how big a file it can theoretically handle?
    – sfdcfox
    Commented Oct 30, 2020 at 14:33
  • The latter. I know (I think) it can only handle < 4 MB. But what I am looking is for a solid documentation around it (I had quoted that from the docs last year in my other answer but now it's gone), so that client can make decisions accordingly. It's just a use case where we ended up using input instead of file-upload so that you know.
    – Jayant Das
    Commented Oct 30, 2020 at 14:37
  • Just to clarify, I am looking for the limit that the component can accommodate and pass it back on to the controller for the file to be uploaded successfully.
    – Jayant Das
    Commented Oct 30, 2020 at 15:31

1 Answer 1

3

There is no limit on the file size, which is why there's no documentation on such a limit; the component uses an input to provide the file selecting functionality. Here's a quick example I wrote up for you:

<aura:application extends="force:slds">
    <aura:attribute name="selectedFileSize" type="Integer" default="0" />
    <lightning:input type="file" onchange="{!c.show}" label="File" />
    <lightning:formattedNumber value="{!v.selectedFileSize}" />
</aura:application>

({
    show: function(component, event, helper) {
        let fileReader = new FileReader();
        fileReader.onload = $A.getCallback(function() {
            component.set("v.selectedFileSize", fileReader.result.length);
        });
        fileReader.readAsBinaryString(event.getSource().get("v.files")[0]);
    }
})

With an example where I read a 194MB file into this binary string:

Reading 194MB file into memory

5
  • Thanks sfdcfox. I hadn't literally tried it myself. While I will do this as a quick test, but do you know if this is same for LWC as well?
    – Jayant Das
    Commented Oct 30, 2020 at 14:50
  • 1
    @JayantDas Yes, the component is actually LWC under the covers.
    – sfdcfox
    Commented Oct 30, 2020 at 14:58
  • 1
    Actually are you able to pass this file back to the controller and get it saved? What I heard from my team was that that's where the issue was encountered and anything > 4 MB wasn't going through.
    – Jayant Das
    Commented Oct 30, 2020 at 15:13
  • 3
    @JayantDas No, the component to server limit is about 3MB (4MB of base64 encoded data). If you need to upload large files to Salesforce, you would use lightning:fileUpload (2GB limit).
    – sfdcfox
    Commented Oct 30, 2020 at 16:12
  • Yes, that's what was the piece of information I was looking for if that's documented. I would imagine the payload docs referenced in my question is then what should be the reference here.
    – Jayant Das
    Commented Oct 30, 2020 at 17:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .