Skip to content

singleDownloadFileBase64 下载 Base64 文件

function singleDownloadFileBase64(base64Data: string, fileName: string): Promise<void>

下载 Base64 Data URL 表示的图片或文件,触发浏览器保存到本地。

参数

参数名说明类型默认值
base64DataBase64 Data URL,例如 data:image/png;base64,...string必填
fileName保存的文件名,包含扩展名string必填

返回值

返回值说明类型
promise下载触发完成后 resolve 的 PromisePromise<void>

示例

typescript
import { singleDownloadFileBase64 } from '@mingto/tools'

await singleDownloadFileBase64('data:text/plain;base64,SGVsbG8=', 'hello.txt')

await singleDownloadFileBase64(imageDataUrl, 'avatar.png')

注意事项

  • 该函数依赖浏览器 fetch 和文件保存能力。
  • 若需要同时支持普通 Base64 字符串和 URL 下载,可使用 singleDownloadFile