zoukankan      html  css  js  c++  java
  • 文件转base64 base64转文件

        
    文件转base64
    blobToDataURL(blob) {
          let reader = new FileReader();
          reader.onload = function(evt) {
            let base64 = evt.target.result;
            console.log(base64);
          };
          reader.readAsDataURL(blob);
        },
     
    base64转文件
    export function base64ToFile(imgBase64, fileName = "base64.png") {
      const base64ToBlob = function(base64Data) {
        let arr = base64Data.split(","),
          fileType = arr[0].match(/:(.*?);/)[1],
          bstr = atob(arr[1]),
          l = bstr.length,
          u8Arr = new Uint8Array(l);

        while (l--) {
          u8Arr[l] = bstr.charCodeAt(l);
        }
        return new Blob([u8Arr], {
          type: fileType
        });
      };
      const blobToFile = function(newBlob, fileName) {
        newBlob.lastModifiedDate = new Date();
        newBlob.name = fileName;
        const files = new window.File([newBlob], fileName);
        return files;
      };
      return blobToFile(base64ToBlob(imgBase64), fileName);
    }
    肖cc QQ2398506993
  • 相关阅读:
    Noip2017 提高组初赛 游(baozha)记
    bzoj4557
    MVVM
    当下较热web前端技术汇总
    JQ 常见demo
    各种宽高
    JQuery 总结
    自定义滚动条配合鼠标滚轮demo
    H5 触摸事件
    SQL必备知识点
  • 原文地址:https://www.cnblogs.com/alecc1124/p/14763787.html
Copyright © 2011-2022 走看看