阅读 151

Cannot set property name of #<File> which has only a getter

上传包含特殊符号的附件到OSS,下载时报错,用正则过滤特殊符号

let pattern = new RegExp(
      /[(\ )(\¥)(\`)(\~)(\<)(\>)(\·)(\…)(\!)(\@)(\#)(\$)(\%)(\^)(\&)(\*)(\()(\))(\-)(\_)(\+)(\=)(\[)(\])(\{)(\})(\|)(\\)(\;)(\:)(\')(\")(\,)(\/)(\<)(\>)(\?)(\)]+/
    )
复制代码

直接使用replace过滤会报错

String(file.name).replace(pattern, '')
复制代码

直接更改filename,会报:annot set property name of # which has only a getter,设置属性为可写就好

  Object.defineProperty(files[i], 'name', {
          writable: true, //设置属性为可写
        })
复制代码
文章分类
前端
文章标签