Appearance
singleDownloadFileBase64 下载 Base64 文件
function singleDownloadFileBase64(base64Data: string, fileName: string): Promise<void>
下载 Base64 Data URL 表示的图片或文件,触发浏览器保存到本地。
参数
| 参数名 | 说明 | 类型 | 默认值 |
|---|---|---|---|
| base64Data | Base64 Data URL,例如 data:image/png;base64,... | string | 必填 |
| fileName | 保存的文件名,包含扩展名 | string | 必填 |
返回值
| 返回值 | 说明 | 类型 |
|---|---|---|
| promise | 下载触发完成后 resolve 的 Promise | Promise<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。