diff options
author | suntala <33031346+suntala@users.noreply.github.com> | 2018-09-28 16:09:48 +0200 |
---|---|---|
committer | suntala <33031346+suntala@users.noreply.github.com> | 2018-09-28 16:09:48 +0200 |
commit | 52f8b882a62ef6819fba5a801dbd4f50bd191f50 (patch) | |
tree | 788791bd15929e32d3119f42799a9c5866a45316 /src | |
parent | 39a872acbaf30f66eb8aadb5114649d0231f4d99 (diff) |
Check if file exists before selecting it. #603
Diffstat (limited to 'src')
-rw-r--r-- | src/components/ContactDetails/ContactDetailsAvatar.vue | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/src/components/ContactDetails/ContactDetailsAvatar.vue b/src/components/ContactDetails/ContactDetailsAvatar.vue index 63cfb8ed..8e7a2249 100644 --- a/src/components/ContactDetails/ContactDetailsAvatar.vue +++ b/src/components/ContactDetails/ContactDetailsAvatar.vue @@ -57,18 +57,20 @@ export default { }, methods: { processFile(event) { - let file = event.target.files[0] - let reader = new FileReader() - let self = this - // check if photo property exists to decide whether to add/update it - reader.onload = function(e) { - self.contact.photo - ? self.contact.photo = reader.result - : self.contact.vCard.addPropertyWithValue('photo', reader.result) + if (event.target.files) { + let file = event.target.files[0] + let reader = new FileReader() + let self = this + // check if photo property exists to decide whether to add/update it + reader.onload = function(e) { + self.contact.photo + ? self.contact.photo = reader.result + : self.contact.vCard.addPropertyWithValue('photo', reader.result) - self.$store.dispatch('updateContact', self.contact) + self.$store.dispatch('updateContact', self.contact) + } + reader.readAsDataURL(file) } - reader.readAsDataURL(file) }, toggleSize() { // maximise or minimise avatar photo |