diff options
author | John Molakvoæ <skjnldsv@users.noreply.github.com> | 2016-05-09 10:00:34 +0200 |
---|---|---|
committer | skjnldsv <fremulon@protonmail.com> | 2016-05-09 13:13:02 +0200 |
commit | f026e4660679799673fd42b60214f656cb812a32 (patch) | |
tree | 7334bf6271a14d01f0f7d0fba37f014e1d11c37a | |
parent | 16f1fa2dfde93c4b56997ed2f5cc39d1a0f80673 (diff) |
Add file size limitation and error popup (1MB)
-rw-r--r-- | js/components/avatar/avatar_directive.js | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/js/components/avatar/avatar_directive.js b/js/components/avatar/avatar_directive.js index 7e5b56e9..225b4d84 100644 --- a/js/components/avatar/avatar_directive.js +++ b/js/components/avatar/avatar_directive.js @@ -11,17 +11,21 @@ angular.module('contactsApp') var input = element.find('input'); input.bind('change', function() { var file = input.get(0).files[0]; - var reader = new FileReader(); + if (file.size > 1024*1024) { // 1 MB + OC.Notification.showTemporary(t('contacts', 'The selected image is too big (max 1MB)')); + } else { + var reader = new FileReader(); - reader.addEventListener('load', function () { - scope.$apply(function() { - scope.contact.photo(reader.result); - ContactService.update(scope.contact); - }); - }, false); + reader.addEventListener('load', function () { + scope.$apply(function() { + scope.contact.photo(reader.result); + ContactService.update(scope.contact); + }); + }, false); - if (file) { - reader.readAsDataURL(file); + if (file) { + reader.readAsDataURL(file); + } } }); }, |