ng2-file-upload onWhenAddingFileFailed问题

时间:2018-11-05 14:09:50

标签: angular upload ng2-file-upload

我希望输出的错误消息超出文件大小或错误文件类型的最大值。我用开关做了解决方案...

我有以下问题: 第一次上传太大文件或错误文件类型时,我会收到一条消息,但是当我重复时,我什么也看不到...

您知道我做错了吗?开关盒不正确吗?

  public uploader: FileUploader;
  public hasBaseDropZoneOver = false;
  public hasAnotherDropZoneOver = false;


  public message: string;
  public alertType = 'success';
  
  constructor() {
  const currentUser = JSON.parse(localStorage.getItem('currentUser'));
    if (currentUser && currentUser.auth_token) {
      this.uploader = new FileUploader({
        url: `${environment.baseUrl}/upload`,
        maxFileSize: 2 * 1024 * 1024,
        allowedFileType: ['csv', 'xls', 'xlsx'],
        authToken: `Bearer ${currentUser.auth_token}`,
      });
      
      this.uploader.onWhenAddingFileFailed = (item: any, filter: any, options: any) => {
        switch (filter.name) {
          case 'fileSize':
            this.message = 'Die max. Dateigröße wurde überschritten!';
            this.alertType = 'error';
            break;
          case 'fileType':
            this.message = 'Dieser Dateityp ist nicht zulässig!';
            this.alertType = 'error';
            break;
        }
      };
  }
  

0 个答案:

没有答案