Am using LightningFileUpload component with Multiple set to false.But i still get the option to upload multiple files, upload button is not disabled after single file upload. Will this false attribute not work? Any work around for this?
2 Answers
The multiple
attribute prevents the user from selecting multiple files at a time. It does not prevent the user from uploading more files to a record.
You will need to find out how many files the record has and dynamically enable/disable the upload button. For example, implement an aura enabled apex method that returns a list of content document link records for a given record ID, and use the count of records returned to the frontend to determine whether the upload button should be enabled or disabled.
based on Akiradev's answer, I remembered I did something similar in a project:
@AuraEnabled
public static ContentVersion getExistingFile(String recordId){
List<ContentDocumentLink> cdls = [SELECT ContentDocumentId FROM ContentDocumentLink WHERE LinkedEntityId = :recordId LIMIT 1];
if(cdls.size() == 0) {
return null;
}
return [SELECT ContentDocumentId, FileType, Title, PathOnClient FROM ContentVersion WHERE ContentDocumentId = :cdls[0].ContentDocumentId LIMIT 1];
}
My UseCase was a bit different, I needed to show the file in the FileUpload Cmp (which was custom developed), but based on this method you can write your method which just returns a boolean if there are files and false if there are no files.
Hope this helps you also.
Regards, Bernhard