9

I have been experimenting with LockerService and found that the files array that should be available in JavaScript for file input types is not available when LockerService is enabled.

Component Markup

<input type="file"
    aura:id="file"
    class="slds-button slds-button--brand"
    onchange="{!c.handleFileChange}" />
<ui:outputText aura:id="buttonText" value="Select File"/>

Component JS

var fileComp = component.find("file");
var file = fileComp.getElement().files[0]; // files is undefined

Note that the value attribute is available. It is just the files array that is not.

Is there an alternative way to get at the file? If not, is this something that will be supported eventually?

The Salesforce Lightning CLI did not report the files array as an error.

1
  • 2
    I also ran into this issue, so I thought let's try a drag&drop file transfer. This worked to the point where you can access the files array, but then you'll notice that the elements in the array aren't of type File, but of type Object, which gives some additional errors if you want to actually read the files (such as readAsDataURL). This is also confirmed to be a LockerService bug by SF. It's not really a solution to your question, but I thought it might be nice to have as additional information. success.salesforce.com/issues_view?id=a1p3A000000IYr8QAG
    – Folkert
    Jun 27, 2016 at 14:44

1 Answer 1

4

Peter, files is not part of the whitelist of attributes that can be inspected from a secure DOM element. Just open a case for this, and we can get it exposed.

1
  • 2
    Is this to be enabled on a case by case basis or something to be added into the LockerService core?
    – drakored
    Aug 15, 2016 at 14:53

You must log in to answer this question.

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