base64 转为blob 触发下载

/**
   * base64转为blob然后触发下载
   */
  base64toBlob(base64: string, filename: string, contentType = 'application/msword') {
    const url = `data:${contentType};base64,${base64}`;
    // console.log(url);
    fetch(url).then(res => res.blob())
      .then(blob => {
        const aTag = document.createElement('a');
        aTag.download = filename;
        aTag.href = URL.createObjectURL(blob);
        aTag.click();
        // 调用此方法,让浏览器知道不再保留对文件的引用。
        URL.revokeObjectURL(aTag.href);
      });
  }

已发布

分类

,

作者:

标签

评论

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注