From 9c3043d40a51bc548da26d6c353723bb1ca6f1f2 Mon Sep 17 00:00:00 2001 From: David Arnold Date: Sun, 13 Sep 2020 21:12:52 -0500 Subject: [PATCH] Ref: Avatar upload handler --- client/components/users/userAvatar.js | 43 +++++++++++++-------------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/client/components/users/userAvatar.js b/client/components/users/userAvatar.js index 22e5af524..145a5fdee 100644 --- a/client/components/users/userAvatar.js +++ b/client/components/users/userAvatar.js @@ -220,28 +220,27 @@ BlazeComponent.extendComponent({ this.$('.js-upload-avatar-input').click(); }, 'change .js-upload-avatar-input'(event) { - let file, fileUrl; - - FS.Utility.eachFile(event, f => { - try { - file = Avatars.insert(new FS.File(f)); - fileUrl = file.url(this.avatarUrlOptions()); - } catch (e) { - this.setError('avatar-too-big'); - } - }); - - if (fileUrl) { - this.setError(''); - const fetchAvatarInterval = window.setInterval(() => { - $.ajax({ - url: fileUrl, - success: () => { - this.setAvatar(file.url(this.avatarUrlOptions())); - window.clearInterval(fetchAvatarInterval); - }, - }); - }, 100); + const self = this; + if (event.currentTarget.files && event.currentTarget.files[0]) { + const uploader = Avatars.insert( + { + file: event.currentTarget.files[0], + streams: 'dynamic', + chunkSize: 'dynamic', + }, + false, + ); + uploader.on('uploaded', (error, fileObj) => { + if (!error) { + self.setAvatar(fileObj.path); + // self.setAvatar(this.currentData().url(this.avatarUrlOptions())); + } + }); + uploader.on('error', (error, fileObj) => { + // XXX check for actually returned error + self.setError('avatar-too-big'); + }); + uploader.start(); } }, 'click .js-select-avatar'() {