function dataURLtoFile(dataurl, filename = 'file') {
          let arr = dataurl.split(',')
          let mime = arr[0].match(/:(.*?);/)[1]
          let suffix = mime.split('/')[1]
          let bstr = atob(arr[1])
          let n = bstr.length
          let u8arr = new Uint8Array(n)
          while (n--) {
              u8arr[n] = bstr.charCodeAt(n)
          }
          return new File([u8arr], `${filename}.${suffix}`, {
              type: mime
          })
      }
      var base64Img = imgDataUrl // base64编码的图片
      var imgFile = dataURLtoFile(base64Img)
      console.log('imgFile====>', imgFile)

 

posted on 2019-03-21 12:28  刘小北~!  阅读(2085)  评论(0编辑  收藏  举报