0

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?

0

2 Answers 2

0

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.

1
  • Yes, i got it now, thank you for responding.
    – Raji Mohan
    Commented Aug 20, 2020 at 10:55
0

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

1
  • Sure, thank you, this helps a lot.
    – Raji Mohan
    Commented Aug 20, 2020 at 10:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .