瀏覽代碼

Ref: pass through image size error message (correctly)

David Arnold 4 年之前
父節點
當前提交
1875551a93
共有 2 個文件被更改,包括 5 次插入4 次删除
  1. 1 2
      client/components/users/userAvatar.js
  2. 4 2
      models/avatars.js

+ 1 - 2
client/components/users/userAvatar.js

@@ -239,8 +239,7 @@ BlazeComponent.extendComponent({
               }
               }
             });
             });
             uploader.on('error', (error, fileData) => {
             uploader.on('error', (error, fileData) => {
-              // XXX check for actually returned error
-              self.setError('avatar-too-big');
+              self.setError(error.reason);
             });
             });
             uploader.start();
             uploader.start();
           }
           }

+ 4 - 2
models/avatars.js

@@ -15,8 +15,10 @@ Avatars = new FilesCollection({
   collectionName: 'avatars',
   collectionName: 'avatars',
   allowClientCode: true,
   allowClientCode: true,
   onBeforeUpload(file) {
   onBeforeUpload(file) {
-    if (file.size <= 72000 && file.isImage) return true;
-    return 'Please upload image, with size equal or less than 72KB';
+    if (file.size <= 72000 && file.type.startsWith("image/")) {
+      return true;
+    };
+    return 'avatar-too-big';
   },
   },
   onAfterUpload: createOnAfterUpload(avatarsBucket),
   onAfterUpload: createOnAfterUpload(avatarsBucket),
   interceptDownload: createInterceptDownload(avatarsBucket),
   interceptDownload: createInterceptDownload(avatarsBucket),