Currently, I am able to pass a single file from the lightning component to the apex controller. But please let me know how to pass multiple files to the apex controller.
Here I need to pass multiple files (listFile) to the apex controller.
public with sharing class FileUploadController {
@AuraEnabled
public static Id SaveFile(Id parentId, String fileName, String base64Data, String contentType) {
base64Data = EncodingUtil.urlDecode(base64Data, 'UTF-8');
Attachment attach = new Attachment();
attach.parentId = parentId;
attach.Body = EncodingUtil.base64Decode(base64Data);
attach.Name = fileName;
attach.ContentType = contentType;
Insert attach;
return attach.Id;
}
}
JavaScript controller:
sampleFunction: function(component, event, helper) {
var index = event.target.dataset.index;
var listFile = component.get("v.listFile");
listFile.splice(index, 1);
component.set("v.listFile", listFile);
}