• toBlob 兼容性:
    在最新版chrome和firefox中能正常使用,在Safari中报错:没有这个函数

  • 规避方法:
    不使用toBlob,使用toDataURL()将file转成base64编码,然后转成blob,如果需要,可以再转成file
    以下为在vue中的写法:

                        var file = this.blobToFile(this.dataURItoBlob(this.form.headPicSrc), 'file')
                        this.formData.append('avatar', file)
        dataURItoBlob (dataURI) {
            let arr = dataURI.split(',')
            let mime = arr[0].match(/:(.*?);/)[1]
            let bstr = atob(arr[1])
            let n = bstr.length
            let u8arr = new Uint8Array(n)
            while (n--) {
                u8arr[n] = bstr.charCodeAt(n)
            }
            return new Blob([u8arr], {type: mime})
        },
        blobToFile (theBlob, fileName) {
            theBlob.lastModifiedDate = new Date()
            theBlob.name = fileName
            return theBlob
        }

相关文章:

  • 2021-10-09
  • 2022-02-18
  • 2021-11-29
  • 2021-12-12
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-11-27
  • 2022-12-23
  • 2021-09-23
  • 2022-01-21
  • 2022-12-23
  • 2021-12-22
相关资源
相似解决方案