コンテンツにスキップ

はじめに

ターミナル ウィンドウ
bun add @capgo/capacitor-downloader
bunx cap sync
import { CapacitorDownloader } from '@capgo/capacitor-downloader';

新しいダウンロードタスクを開始

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

ダウンロードを一時停止 ダウンロードは後で同じ位置から再開できます

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

resume

再開

ダウンロードを再開します。 再開した位置から続きます。

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

stop

終了

ダウンロードを終了し、削除します。 ダウンロードしたデータは削除されます。

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

クリップボードにコピー

import { CapacitorDownloader } from '@capgo/capacitor-downloader';
await CapacitorDownloader.checkStatus({} as { id: string });

ダウンロードファイルの情報を取得します。

import { CapacitorDownloader } from '@capgo/capacitor-downloader';
await CapacitorDownloader.getFileInfo({} as { path: string });

タイプ リファレンス

タイプ リファレンス

ダウンロードを開始するために使用する設定オプションです。

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';
}

ダウンロードタスクの現在の状態と進行状況を表します。

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. Re-run the sync when the public API changes upstream.