Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

179
Views
How to limit the maximum uploads in Angular

How should i limit the maximum 5 uploads in a single input file in angular

<input type="file" class="form-control" id="inputGroupFile" 
onChange="uploadMultipleFiles($event)" > 

app.component.ts:

uploadMultipleFiles(files) {
  if (files.length > 3) {
   this.alertService.error("length exceeded; files have been truncated");
   let list = new DataTransfer;
   for (let i = 0; i < 3; i++)
    list.items.add(files[i]);
  }
}

Thanks

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Like the below code, you can prevent the limit of file upload.

filesData(files, event): void {
  
    if (event.target.files.length > 5) {
      alert("Only 5 files allow");

      event.preventDefault();
      event.value = ""; // clear the older value 
    } else {
        //Put your Business logic here
    }
  }

Also, pass the $event as an argument to the function on the calling the onChange method.

 <input type="file" multiple #file (change)="filesData($event)" />
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!