base64图片转成文件流再转成链接 vue js
生活随笔
收集整理的這篇文章主要介紹了
base64图片转成文件流再转成链接 vue js
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
獲取的鏈接格式 ,只能在本地打開
blob:http://localhost:8080/c5b2915d-5f72-4918-bc7a-f9fb74aaba05
// img 是base64圖片完整字符串 getUrl(img){let file = this.base64ImgtoFile(img); // 獲取文件流let imgUrl = window.webkitURL.createObjectURL(file) ||window.URL.createObjectURL(file); // 獲取鏈接 }, // 獲取文件流base64ImgtoFile(dataurl, filename = "file") {const arr = dataurl.split(",");const mime = arr[0].match(/:(.*?);/)[1];const suffix = mime.split("/")[1];const bstr = atob(arr[1]);let n = bstr.length;const u8arr = new Uint8Array(n);while (n--) {u8arr[n] = bstr.charCodeAt(n);}return new File([u8arr], `${filename}.${suffix}`, {type: mime,});},總結
以上是生活随笔為你收集整理的base64图片转成文件流再转成链接 vue js的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 围棋入门(完整版)
- 下一篇: Vue入门教程 第五篇 (组件)