bergben / ng2-file-input

Angular 2 component that implements a drag and drop or select file selection, including preview.
MIT License
25 stars 11 forks source link

How to validate image size? (ex: less than 2MB) #16

Closed DamithaPerera closed 6 years ago

DamithaPerera commented 7 years ago

public onAction(event: any) { this.resImagesSize = event.currentFiles; for (let i = 0; i < this.resImagesSize[i].size; i++) { if (this.resImagesSize[i].size > 2000000) { this.toasterService.pop('error', 'Error', 'Please upload less than 2MB image'); this.resImagesSize.splice(i, 1); } else { this.resImages = this.resImagesSize; } } }

Is there any way to validate ?, because I tried to validate like this... but the problem is when i upload more than 2 images it display 2 popup messages..... any solution ??

bergben commented 6 years ago

Hi @DamithaPerera.

you'd have to check if there is already a toast like that existing or usually you can set up not to show duplicate toasts with the toast libraries. Closing this as this is not really a ng2-file-input library code related issue...