From f9c6cc077b314fa3937d8e30ba162d4ab5b59fb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98yvind=20St=C3=B8rkersen?= Date: Thu, 1 Dec 2016 21:17:50 +0100 Subject: [PATCH] New beforeUpload event - makes it possible to validate files before the upload starts (#142) beforeUpload event - validate file (size) before upload starts --- README.md | 14 ++++++++++++-- package.json | 2 +- src/directives/ng-file-drop.ts | 7 ++++++- src/directives/ng-file-select.ts | 7 ++++++- src/services/ng2-uploader.ts | 9 ++++++++- 5 files changed, 33 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 80aaa66c..93c5d895 100644 --- a/README.md +++ b/README.md @@ -65,6 +65,7 @@ export class DemoApp { options: Object = { url: 'http://localhost:10050/upload' }; + sizeLimit = 2000000; handleUpload(data): void { if (data && data.response) { @@ -76,6 +77,13 @@ export class DemoApp { fileOverBase(e:any):void { this.hasBaseDropZoneOver = e; } + + beforeUpload(uploadingFile): void { + if (uploadingFile.size > this.sizeLimit) { + uploadingFile.setAbort(); + alert('File is too large'); + } + } } ```` @@ -84,7 +92,8 @@ export class DemoApp { + (onUpload)="handleUpload($event)" + (beforeUpload)="beforeUpload($event)">