blob 转file及下载


1. blob转file

 blobToFile (theBlob) {
      let file = new window.File([theBlob], '文件名字', {type: 'image/jpeg'})
 }

 

2. dataUrl转blob

this.$refs['当前图片定义的ref'].toBlob(blob => {
        let a = document.createElement('a')
        document.body.appendChild(a)
        a.style = 'display: none'
        this.blobUrl = window.URL.createObjectURL(blob)
        a.href = this.blobUrl
        a.download = this.url
        a.click()
        document.body.removeChild(a)
        window.URL.revokeObjectURL(this.blobUrl) // 下载图片
      }, 'image/jpeg')

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM