【问题标题】:set the default 'No file choosen' in file uploader instead of the image name when user tries to upload a large image当用户尝试上传大图像时,在文件上传中设置默认的“未选择文件”而不是图像名称
【发布时间】:2021-01-10 14:14:28
【问题描述】:

这是我上传无效图片时得到的。带有图片名称的标签上传

下面是.ts文件中的代码

const fileSize = files[0].size;

if((fileSize / 1024) > 50) {
  this.errorMessage = '*Image size cannot exceed 50KB.';      
  return;
}

const reader = new FileReader();
this.fileName = files[0].name;
reader.onloadend = () => {
  this.userFileInfo = reader.result;
  this.imgURL = this.userFileInfo;
};
this.changeFile(files[0]).then((): any => { });
reader.readAsDataURL(files[0]);

}

这里是 HTML 代码

 <div class="col-md-8">
       <label for="userName" class="primary-label lable-position">Profile picture</label>
       <input #file type="file" class="" accept='image/* (change)="preview(file.files)" />
 </div> 

上传无效图片时,我想将标签设置为默认值“未选择文件”,如下所示

我该怎么做?

【问题讨论】:

    标签: angular image file-upload


    【解决方案1】:

    我已尝试为文件上传器指定样式。

     element.style {
            width: 98%;
            background-color: white;
        }
    

    现在它看起来像下面没有文件名。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-06-06
      • 2018-01-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-06-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多