limit the number of files to upload

1 Answer 855 Views
Upload
Sean
Top achievements
Rank 1
Sean asked on 25 May 2021, 04:56 AM
How can I limit the number of files to upload with the Kendo UI Upload widget?  

1 Answer, 1 is accepted

Sort by
0
Martin
Telerik team
answered on 27 May 2021, 11:33 AM

Hello, Sean,

As the Upload does not have a built-in file number limitation, you can use the code below to achieve the requirement.

function select(e) {
    var files = e.sender.getFiles();
        if (files.length >= 5) {
            alert("Please select max 5 files.");
            e.preventDefault();
        }
}
Here is a small example for reference.

Let me know if you have any further questions.

Regards,
Martin
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Mark
Top achievements
Rank 1
commented on 22 Nov 2024, 12:24 AM

What if the max = 3 files.  First time, user selects 2 files, but files are not auto uploaded...Then user selects 2 more files...How can I stop them and or just add 1 file so that it equals 3 before I upload them?  Thanks

 

Martin
Telerik team
commented on 26 Nov 2024, 11:32 AM

Hello, Mark,

The code can be modified as in this Dojo example to prevent selecting more than 5 files. I am not sure if it would be possible to only select 1 in order to fit the max files allowed. A custom logic will also need to be added to reduce the variable that stores the number of the selected files when the user removes a file from the Upload list.

Tags
Upload
Asked by
Sean
Top achievements
Rank 1
Answers by
Martin
Telerik team
Share this question
or