解决: 图片上传File对象不兼容IE

最近做公司业务, 上传图片出问题了~

首先是要求前端传递的图片名称不能是中文 ??? image.png

解决办法:
我们讨论决定以时间戳命名

new File([file], new Date().getTime() + '.' + 文件后缀名 ,{ type: file.type });

问题又来了, new File在ie下报错,也就是说在ie下调用上传图片功能是无效的
解决办法: File不识别的话重写一下

let File = window.File

try {
  new File([], '')
} catch(e) {
  File = class File extends Blob {
    constructor(chunks, filename, opts = {}){
      super(chunks, opts)
      this.lastModifiedDate = new Date()
      this.lastModified =+ this.lastModifiedDate
      this.name = filename
    }
  }
}

OVER
and on...

你可能感兴趣的:(javascript)