跳过内容

开始

GitHub

您可以使用我们的 AI 助手设置来安装插件。使用以下命令将 Capgo 技能添加到您的 AI 工具中:

终端窗口
npx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-plugins

然后使用以下提示:

Use the `capacitor-plugins` skill from `Cap-go/capgo-skills` to install the `@capgo/capacitor-downloader` plugin in my project.

如果您prefer手动设置,安装插件并运行以下命令,然后遵循以下平台特定的说明:

终端窗口
bun add @capgo/capacitor-downloader
bunx cap sync
import { CapacitorDownloader } from '@capgo/capacitor-downloader';

API 简介

API 简介

开始一个新的下载任务。

import { CapacitorDownloader } from '@capgo/capacitor-downloader';
const task = await CapacitorDownloader.download({
id: 'my-download',
url: 'https://example.com/file.pdf',
destination: 'downloads/file.pdf'
});

暂停一个正在下载的任务。 下载可以在同一位置从暂停处恢复。

import { CapacitorDownloader } from '@capgo/capacitor-downloader';
await CapacitorDownloader.pause({ id: 'id-123' });

恢复一个暂停的下载。 从暂停处继续下载。

import { CapacitorDownloader } from '@capgo/capacitor-downloader';
await CapacitorDownloader.resume({ id: 'id-123' });

永久停止和取消下载。 下载的数据将被删除。

import { CapacitorDownloader } from '@capgo/capacitor-downloader';
await CapacitorDownloader.stop({ id: 'id-123' });

检查下载的当前状态。

import { CapacitorDownloader } from '@capgo/capacitor-downloader';
const result = await CapacitorDownloader.checkStatus({ id: 'id-123' });
console.log(result);

获取下载的文件信息。

import { CapacitorDownloader } from '@capgo/capacitor-downloader';
const result = await CapacitorDownloader.getFileInfo({ path: 'path/to/file' });
console.log(result);

DownloadOptions

下载选项

下载启动配置选项

export interface DownloadOptions {
/** Unique identifier for this download task */
id: string;
/** URL of the file to download */
url: string;
/** Local file path where the download will be saved */
destination: string;
/** Optional HTTP headers to include in the request */
headers?: { [key: string]: string };
/** Network type requirement for download */
network?: 'cellular' | 'wifi-only';
/** Download priority level */
priority?: 'high' | 'normal' | 'low';
}

DownloadTask

下载任务

下载任务的当前状态和进度

export interface DownloadTask {
/** Unique identifier for the download task */
id: string;
/** Download progress from 0 to 100 */
progress: number;
/** Current state of the download */
state: 'PENDING' | 'RUNNING' | 'PAUSED' | 'DONE' | 'ERROR';
}

重新同步公共资源__CAPGO_KEEP_0__时 src/definitions.ts当公共API上游发生变化时,请重新运行同步。

继续从开始

继续从开始

如果您正在使用 入门指南 来规划仪表板和API操作,连接它与 使用@capgo/capacitor-下载器 为native能力在使用@capgo/capacitor-下载器 API概述 为实现细节在API概述 介绍 为实现细节在介绍 API密钥 为实现细节在API密钥, 设备 __CAPGO_KEEP_0__