axios 使用base64文件上传

public handleSaveWatermark() {
    const e = canvas.toDataURL({
      multiplier: 1,
    });

    function dataURLtoFile(dataUrl, filename) {
      const arr = dataUrl.split(',');
      const mime = arr[0].match(/:(.*?);/)[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, { type: mime });
    }

    const file = dataURLtoFile(e, 'hello.txt');
    console.log(file);

    const uploadFormData = new FormData();
    uploadFormData.append('file', file);
    // 使用 axios 进行文件上传的请求
    axios.post(`${BASE_URL}/platform/hg/goods/v1/image/singleimgupload`, uploadFormData, {
      withCredentials: true,
    });
  }