4

I created a lightning component based this tutorial.

I found out file attribute in <input type="file" /> was not whitelisted in the locker service as mentioned in this post.

It looks like now file attribute is whitelisted as I am able to get the file object. Now, the problem is I'm trying to read the file content using the readDataAsURL of the FileReader it is throwing an error like this:

TypeError: Argument 1 of FileReader.readAsDataURL does not implement interface Blob.

cmp code:

<aura:component controller="FileController">
    <aura:attribute name="parentId" type="Id" />
    <input type="file" aura:id="file" />
    <ui:button label="save" press="{!c.save}" />
</aura:component>

controller.js:

save : function(component, event, helper) {
        var MAX_FILE_SIZE = 750000;
        var fileInput = component.find('file').getElement();
        console.log('fileInput', fileInput); 
        console.log('file', fileInput.files[0]); // this return file object
        var file1 = fileInput.files[0];
        if(file1.size > MAX_FILE_SIZE) {
            console.log('File size exceeded the maximum upload limit.');
            return false;
        }

        var fr = new FileReader();

        var self = this;
        fr.onload = function(){
            var fileContents = fr.result;
            var base64Mark = 'base64,';
            var dataStart = fileContents.indexOf(base64Mark) + base64Mark.length;
            fileContents = fileContents.substring(dataStart);
            self.upload(component, file1, fileContents);
        };
        fr.readAsDataURL(file1); // this doesn't work
    }

2 Answers 2

3

Thank you for the details and the repro steps. The FileReader, the FileList and the File objects are now whitelisted and should be available later this week, most likely on Wednesday.

2

Not sure if you saw this, but Salesforce just posted an update that his has been resolved: Locker Service - FileReader.readAsDataURL() does not work with File reference. I have not personally tried it but looks promising.

You must log in to answer this question.

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