Skip to content

batchDownloadFile 批量下载文件

function batchDownloadFile(fileList: Array<{ filePath: string; fileName?: string }>, zipName: string): Promise<void>

批量下载文件并打包为 ZIP。逐个拉取文件后打包为 ZIP 并触发浏览器下载。

参数

参数名说明类型默认值
fileList文件列表,每项包含文件路径和可选文件名Array<{ filePath: string; fileName?: string }>必填
zipNameZIP 文件名;未以 .zip 结尾时会自动补齐string必填

返回值

返回值说明类型
promise打包并触发下载后 resolve 的 PromisePromise<void>

示例

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

await batchDownloadFile([
  { filePath: 'https://example.com/a.pdf' },
  { filePath: 'https://example.com/b.png', fileName: 'image.png' },
], 'attachments')
// 下载 attachments.zip

注意事项

  • 文件下载失败时会抛出 Error('批量下载失败,部分文件下载出错。')
  • 该函数依赖浏览器环境、axiosfile-saverjszip