We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

limit the number of files upload

Thread ID:

Created:

Updated:

Platform:

Replies:

143409 Mar 19,2019 01:59 PM UTC Mar 20,2019 04:54 PM UTC React - EJ 2 1
loading
Tags: Uploader
TOKO FIDELE
Asked On March 19, 2019 01:59 PM UTC

Hello, 

I am currently using the Uploader component to upload my files to the server. the problem is that I can not limit the number of files to upload. I would like the user to have a maximum of 3 files to upload and return an error message if he tries to add more than 3.

Thanks in advance and regards,

 

Prince Oliver [Syncfusion]
Replied On March 20, 2019 04:54 PM UTC

Hi Toko, 

Thank you for contacting Syncfusion support. 

We have checked your requirement for adding limit to upload the file into uploader.  We have two solution for this case. 

Solution 1

We have prepared sample based on your requirement, get the selected file length from “selected“ event and check the limit “count“. If the count is higher than the selected file then, call args.cancel and show error message. We have alerted the error message for maximum of 3 files to upload. Please find the sample for your reference. 

onFileSelect(args) { 
    var fileLength = args.filesData.length + this.uploadObj.getFilesData().length; 
    if (fileLength > this.count) { 
        args.cancel = true; 
        document.getElementsByClassName('e-error')[0].innerHTML = 'maximum of ' + this.count + ' files to upload'; 
    } else { 
        document.getElementsByClassName('e-error')[0].innerHTML = ''; 
    } 
} 

  
Solution 2

if you need to exceed the file length and upload only the limited files use the below sample. 

onFileSelect(args) { 
    var fileLength = args.filesData.length + this.uploadObj.getFilesData().length; 
    // if you need upload first 3 files means use this way. 
    if (fileLength > this.count) { 
        args.filesData.splice(this.count, args.filesData.length); 
        alert('maximum of ' + this.count + ' files to upload') 
        document.getElementsByClassName('e-error')[0].innerHTML = 'maximum of ' + this.count + ' files to upload'; 
    } else { 
        document.getElementsByClassName('e-error')[0].innerHTML = ''; 
    } 
} 


Please let us know if you need any further assistance on this. 

Regards, 
Prince 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;