+ Start a Discussion
Madhusudan Singh 15Madhusudan Singh 15 

Fileupload lightning controller not working

Hi All,

I am new to lightning and trying use file upload lightning components. 

I used exact same code which is mentioned in salesforce website
https://developer.salesforce.com/docs/component-library/bundle/lightning:fileUpload/example
just replaced recordid to my account id

But it is not working.

Please help me on this

Thanks in Advance
Best Answer chosen by Madhusudan Singh 15
mukesh guptamukesh gupta
Hi,

Please use below code it's tested my side:-
 
<aura:component implements="flexipage:availableForRecordHome,force:hasRecordId" access="global" >
    <div>
    	<lightning:fileUpload label="Attach receipt" 
    	 name="fileUploader"
        multiple="true" 
        accept=".pdf, .png, .jpeg, .jpg"
        recordId="{!v.recordId}" 
        onuploadfinished="{!c.handleUploadFinished}" />
    </div>
    
</aura:component>


if you need any assistanse, Please let me know!!

Kindly mark my solution as the best answer if it helps you.

Thanks
Mukesh

 

All Answers

NagendraNagendra (Salesforce Developers) 
Hi Madhu,

I have tried the same piece of code and it is working fine for me.

Could you please let me know what exactly is the error message or the issue you are facing so that we can look into it and can help you accordingly.

It would be of great help if you can post the screenshots of what you have done so far which helps troubleshoot the issue further.

Happy to help further.

Thanks,
Nagendra
Madhusudan Singh 15Madhusudan Singh 15
Hi Nagendra,

FileUpload.cmp
<aura:component implements="flexipage:availableForAllPageTypes" access="global" >
    <aura:attribute name="accept" type="List" default="['.jpg', '.jpeg']"/>
    <aura:attribute name="multiple" type="Boolean" default="true"/>
    <aura:attribute name="disabled" type="Boolean" default="false"/>
                    
    <lightning:fileUpload label="Add attachment" multiple="{!v.multiple}" 
                          accept="{!v.accept}" recordId="0017F00000tN50uQAC" 
                          onuploadfinished="{!c.handleUploadFinished}" />
    
</aura:component>

FileUploadController.js
({
    handleUploadFinished : function(component, event, helper) {
       alert("hello");        
    }
})
Created custom Application which is calling FileUpload component(using this to preview)
 
<aura:application extends="force:slds">
  <c:FileUpload />
</aura:application>

When I am previewing it is not giving alert.
Can you share working code for my reference 
 
mukesh guptamukesh gupta
Hi,

Please use below code it's tested my side:-
 
<aura:component implements="flexipage:availableForRecordHome,force:hasRecordId" access="global" >
    <div>
    	<lightning:fileUpload label="Attach receipt" 
    	 name="fileUploader"
        multiple="true" 
        accept=".pdf, .png, .jpeg, .jpg"
        recordId="{!v.recordId}" 
        onuploadfinished="{!c.handleUploadFinished}" />
    </div>
    
</aura:component>


if you need any assistanse, Please let me know!!

Kindly mark my solution as the best answer if it helps you.

Thanks
Mukesh

 
This was selected as the best answer
Cuong 9Cuong 9
I encountered the same issue and can't fixed it. Do any guys know why?
Cuong 9Cuong 9
It seems some people are confronting here with these problem but no one has a clue. 

https://salesforce.stackexchange.com/questions/224710/lightning-file-upload-component-event-not-firing
Bishwambhar SenBishwambhar Sen
lightning:fileUpload component doesn't work in lightning out or standalone app. Try dragging your component in a lightning page and it will work. Refer this post. It explains the same problem . https://www.sen-force.com/lightningfileupload-and-lightningfilecard-base-components/