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