I have this standard JavaScript code implemented in Lightning component to upload Files which works perfectly when LockerService is disabled.
Component:
<aura:component >
<input type="file" aura:id="file" onchange="{!c.upload}" />
</aura:component>
Controller:
({
upload : function(component, event, helper) {
helper.save(component);
}
})
Helper:
({
MAX_FILE_SIZE: 4 500 000, /* 6 000 000 * 3/4 to account for base64 */
CHUNK_SIZE: 950 000, /* Use a multiple of 4 */
save : function(component) {
var fileInput = component.find("file").getElement();
var file = fileInput.files[0];
console.log('file type'+typeof file);
if (file.size > this.MAX_FILE_SIZE) {
alert('File size cannot exceed ' + this.MAX_FILE_SIZE + ' bytes.\n' + 'Selected file size: ' + file.size);
return;
}
console.log('blob of file'+JSON.stringify(file));
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, file, fileContents);
};
console.log('before senfin'+JSON.stringify(file));
//fileAdded = (Blob)fileAdded;
//fr.readAsDataURL(file);
fr.readAsArrayBuffer(file); //The error comes up on this line.
}
})
Could anyone please guide me to implement the same with LockerService on?