function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Rakesh keerthi 9Rakesh keerthi 9 

lightning file upload on button click

Hi,

I'm creating a lightning component to upload files. for this I'm using lightning:fileUpload .

But here in my case, I've got a button, when the button is clicked, I want to achieve the same functionality as lightning:fileUpload.

Currently this is what I'm trying out.
 
<aura:component>
    
    <aura:attribute name="multiple" type="Boolean" default="false"/>
    <aura:attribute name="disabled" type="Boolean" default="false"/>
    
    <lightning:fileUpload aura:id="fUploader_1" 
                          name="fileUploader"
                          label= "Demo Upload"
                          multiple="{!v.multiple}"
                          accept="{!v.accept}"
                          disabled="{!v.disabled}"
                          recordId="abcd"
                          onuploadfinished="{!c.handleUploadFinished}"/>
    <lightning:button variant="Brand" label="Base" title="Base action" onclick="{!c.handleClick}"/>
</aura:component>

and js is
 
({
    handleUploadFinished: function (cmp, event) {
        // This will contain the List of File uploaded data and status
        var uploadedFiles = event.getParam("files");
        console.log("Files uploaded : " + uploadedFiles.length);
    },
    handleClick: function (cmp, event) {
        var fileUploader = cmp.find("fUploader_1");
        fileUploader.click();
    }
})

when i run this I get the error as fileUploader.click is not a function

please let me know on how can I get rid of that error and get that functionality.

Thanks
Raj VakatiRaj Vakati
There is no click event in the lightning:fileUpload  ..  I am not sure what is your requirerement .. if you need custom javasctipt events  create a custom component from the scratch 
Dipanshu Singh 7Dipanshu Singh 7
Do you get answer?