I want to upload multiple files from a public site to salesforce ContentDocumentLink. How I can create bulk of files on javascript (client) side and handle them from apex?
Lightning Component:
<lightning:input aura:id="fileId"
onchange="{!c.handleFilesChange}"
type="file"
name="file"
messageWhenTypeMismatch="Please upload supported file types"
accept=".jpg, .pdf, .jpeg, .png"
multiple="true"/>
<button class="slds-button slds-button_neutral" onclick="{!c.doSave}">Upload Files</button>
Controller.js:
doSave: function(component, event, helper) {
var fileCmp = component.find("fileId");
if (!$A.util.isUndefined(fileCmp)) {
if (fileCmp.get("v.files").length > 0) {
// get the selected files using aura:id [return array of files]
var fileInput = component.find("fileId").get("v.files");
// get the first file using array index[0]
var file = fileInput[0];
var self = this;
// create a FileReader object
let objFileReader = new FileReader();
// set onload function of FileReader object
objFileReader.onload = $A.getCallback(function() {
var fileContents = objFileReader.result;
var base64 = 'base64,';
var dataStart = fileContents.indexOf(base64) + base64.length;
fileContents = fileContents.substring(dataStart);
// call the uploadProcess method
self.uploadProcess(component, file, fileContents);
});
objFileReader.readAsDataURL(file);
}
}
This thing works for one file. What I want is to do a callback and pass all the files to handle them on apex.