You need to sign in to do that
Don't have an account?
Karthik j
How to get recordId after file uploading
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) {
var uploadedFiles = event.getParam('files');
//set action to call updatePicturePath method from Server-side controller
var action = component.get('c.updatePicturePath');
//set parametrs
console.log('Id>>'+component.get('v.recordIdforFile'));
var recordId=component.get('v.recordId);
alert(recordId);
action.setParams({
recId : recordId
});
action.setCallback(this, function(response){
var state = response.getState();
alert(state);
if(state === 'SUCCESS' || state === 'DRAFT') {
var resultToast = $A.get("e.force:showTest");
resultToast.setParams({
"title" : "Success!",
"message" : uploadedFiles.length + "file uploadedsuccessfully!"
});
resultToast.fire();;
}
});
$A.enqueueAction(action);
}
I am getting undefined for recordId and I need it to send as a parameter to updatePicturePath APEX method.
<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) {
var uploadedFiles = event.getParam('files');
//set action to call updatePicturePath method from Server-side controller
var action = component.get('c.updatePicturePath');
//set parametrs
console.log('Id>>'+component.get('v.recordIdforFile'));
var recordId=component.get('v.recordId);
alert(recordId);
action.setParams({
recId : recordId
});
action.setCallback(this, function(response){
var state = response.getState();
alert(state);
if(state === 'SUCCESS' || state === 'DRAFT') {
var resultToast = $A.get("e.force:showTest");
resultToast.setParams({
"title" : "Success!",
"message" : uploadedFiles.length + "file uploadedsuccessfully!"
});
resultToast.fire();;
}
});
$A.enqueueAction(action);
}
I am getting undefined for recordId and I need it to send as a parameter to updatePicturePath APEX method.
>> https://developer.salesforce.com/docs/component-library/bundle/lightning:fileUpload/documentation
As mentioned in the above link you can make use of onuploadfinished event that gets triggered after the files are uploaded.
I am adding the piece of snippet along with the information that I found would be useful in the above link:
You must handle the onuploadfinished event, which is fired when the upload is finished.
event.getParam("files") returns a list of uploaded files with the properties name and documented.
>> name: The file name in the format filename.extension, for example, account.jpg.
>> documentId: The ContentDocument Id in the format 069XXXXXXXXXXXX.
>> ContentVersionId: The ContentVersion Id in the format 068XXXXXXXXXXXX.
Note: When a guest user uploads files, the returned list includes only the name and ContentVersionId. The documentId is not returned.
Let me know if it helps you and close your query by marking it as solved so that it can help others in the future.
Thanks.
<aura:attribute name="recordId" type="String" />
<lightning:fileUpload label="Attach receipt"
name="fileUploader"
multiple="true"
accept="{!v.filetype}"
recordId="{!v.recordId}"
onuploadfinished="{!c.handleUploadFinished}" />
Your recordId will be saved in attribute name recordId.
Please Mark it as the best answer if it helps you.
Thanks & regards
Suraj Tripathi