upload multiple file in salesforce lightning

Bynayakdillip

upload multiple file in salesforce lightning

upload multiple file in salesforce lightning

Here I am going to explain how you upload multiple files in the lightning component as well as how you used same in the lightning community.

Create new lightning component with forceCommunity:availableForAllPageTypes implements

<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >
    <aura:attribute name="RecordId" type="String"   default="0017F00000WVzKl"/> 
    <lightning:fileUpload label="Upload File(.pdf, .png,.jpg)"
                          name="fileUploader" 
                          multiple="true" 
                          accept=".pdf, .png,.jpg"
                          recordId="{!v.RecordId}" 
                          onuploadfinished="{!c.handleUploadFinished}" />
    
</aura:component>

Note:Pass your own Record ID like Account RecordID:- 0017F00000WVzKl.i have pass here

Controller JS

({
    handleUploadFinished : function(component, event, helper) {
        
        // Get the list of uploaded files
        var uploadedFiles = event.getParam("files");
        var toastEvent = $A.get("e.force:showToast");
        toastEvent.setParams({
            "title": "Success!",
            "message": "File "+uploadedFiles[0].name+" Uploaded successfully."
        });
        toastEvent.fire();
    }
})

Now Drag your component over community builder then publish it. after successfully publish you can upload file



Also, you can check the files over account object with attached file according to your record ID.

About the author

nayakdillip administrator

Leave a Reply