Hi , I am using the uploader but I want to limit the number of files that the user can select , the uploader is set to manual uploading and user can select multiple files , so if the user select 7 files and the MaxFileLimit is set to 5, I want to add 5 files to the list and removed the rest .
<kendo-upload
[saveUrl]="uploadUrl"
[autoUpload]="false"
[actionsLayout]="actionsLayout"
[restrictions]="imageRestrictions"
(select)="select($event)"
(remove)="remove($event)"
(clear)="clear()"
(upload)="uploadEventHandler($event)"
(complete)="complete()">
<ng-template kendoUploadFileInfoTemplate let-file>
<div><img [src]="findPreview(file)" style="height: 50px;"> Name: {{file[0].name}} </div>
<div *ngIf="file[0].validationErrors">You cannot upload this file :: {{file[0].validationErrors[0]}}</div>
</ng-template>
</kendo-upload>
I have tried using the Select Event to remove the file using e.preventDefault(); but it does stop the process and not files are added to the list if the users select more than 5 files .
publicselect(e: SelectEvent): void {
const that = this;
e.files.forEach((file) => {
if (file.extension === '.jpg') {
if (this.imageCount < this.maxImageCount) {
this.imageCount++
if (!file.validationErrors) {
const reader = newFileReader();
reader.onload = function (ev) {
const image = {
src: ev.target["result"],
uid: file.uid,
};
that.imagePreviews.unshift(image);
};
reader.readAsDataURL(file.rawFile);
}
}else {
e.preventDefault();
}
}
});
}
Any ideas on how to remove the extra files or limit the number of files the user can select .
Thanks