You need to sign in to do that
Don't have an account?

How to Send the uploaded file to Apex using lightning:fileUpload
Component Code
<lightning:fileUpload label="Upload Multiple files"
multiple="false"
accept=".pdf, .png, .jpg"
recordId="{!v.recordId}"
aura:id="multipleUpload"
onuploadfinished="{!c.handleUploadFinished}" />
JScontroller
({
handleUploadFinished: function (component, event, helper) {
// Get the list of uploaded files
var uploadedFiles = event.getParam("files");
alert("Files uploaded length : " + uploadedFiles.length);
}
})
After the Alert How do we retrieve the files uploaded and send it to Apex class ?
Also on the APEX class what is the input parameter type we use for receiving the file sent from the above JS
<lightning:fileUpload label="Upload Multiple files"
multiple="false"
accept=".pdf, .png, .jpg"
recordId="{!v.recordId}"
aura:id="multipleUpload"
onuploadfinished="{!c.handleUploadFinished}" />
JScontroller
({
handleUploadFinished: function (component, event, helper) {
// Get the list of uploaded files
var uploadedFiles = event.getParam("files");
alert("Files uploaded length : " + uploadedFiles.length);
}
})
After the Alert How do we retrieve the files uploaded and send it to Apex class ?
Also on the APEX class what is the input parameter type we use for receiving the file sent from the above JS
Please refer below link it may help you in this regard.
https://teamforcesite.wordpress.com/2017/11/07/winter-18-uploading-files-in-lightning-component/
Please review the documentation:
- https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/aura_compref_lightning_fileUpload.htm
The lightning file upload component, uploads files and attaches it to a record.You specify the record to attach the files to with the below attribute:
recordId => String => The record Id of the record that the uploaded file is associated to.
If you want to validate the files or have some logic to execute on them, use the below callback function provided:
onuploadfinished => Action => The action triggered when files have finished uploading.
The docs show this example of a callback function: As you can see the function receives an event called files that can be inspected.
Thanks,
Nagendra