はじめに
Copy a setup prompt with the install steps and the full markdown guide for this plugin.
Set up this Capacitor plugin in the project.
Use the package manager already used by the project.
Install these package(s): `@capgo/capacitor-downloader`
Run the required Capacitor sync/update step after installation.
Read this markdown guide for the full setup steps: https://raw.githubusercontent.com/Cap-go/website/refs/heads/main/apps/docs/src/content/docs/ja/docs/plugins/downloader/getting-started.mdx
Use that guide for platform-specific steps, native file edits, permissions, config changes, imports, and usage setup.
If that guide references other docs pages, read them too.
インストール
Section titled “インストール”npm install @capgo/capacitor-downloadernpx cap syncyarn add @capgo/capacitor-downloadernpx cap syncpnpm add @capgo/capacitor-downloadernpx cap syncbun add @capgo/capacitor-downloadernpx cap syncimport { CapacitorDownloader } from '@capgo/capacitor-downloader';
// ダウンロードを開始const downloadId = 'my-download-001';await CapacitorDownloader.download({ id: downloadId, url: 'https://example.com/large-file.zip', destination: '/downloads/large-file.zip', headers: { 'Authorization': 'Bearer token123' }, network: 'wifi-only', priority: 'high'});
// 進行状況の更新をリッスンCapacitorDownloader.addListener('downloadProgress', (data) => { console.log(`Download ${data.id}: ${data.progress}% complete`); console.log(`Downloaded: ${data.bytesDownloaded}/${data.totalBytes} bytes`);});
// 完了を処理CapacitorDownloader.addListener('downloadCompleted', (data) => { console.log(`Download completed: ${data.id}`); console.log(`File saved to: ${data.path}`);});
// エラーを処理CapacitorDownloader.addListener('downloadFailed', (error) => { console.error(`Download failed: ${error.id}`, error.message);});
// ダウンロードを一時停止await CapacitorDownloader.pause(downloadId);
// ダウンロードを再開await CapacitorDownloader.resume(downloadId);
// ダウンロードステータスを確認const status = await CapacitorDownloader.checkStatus(downloadId);console.log('Download status:', status);
// ダウンロードを停止await CapacitorDownloader.stop(downloadId);コアAPIメソッド
Section titled “コアAPIメソッド”ダウンロード管理
Section titled “ダウンロード管理”download(options)- 新しいファイルのダウンロードを開始pause(id)- 進行中のダウンロードを一時停止resume(id)- 一時停止したダウンロードを再開stop(id)- ダウンロードを停止してキャンセルcheckStatus(id)- 現在のダウンロードステータスを取得
ファイル操作
Section titled “ファイル操作”getFileInfo(path)- ファイル情報とメタデータを取得
ダウンロード設定
Section titled “ダウンロード設定”interface DownloadOptions { id: string; // 一意のダウンロード識別子 url: string; // ダウンロード元URL destination: string; // ローカル保存パス headers?: Record<string, string>; // カスタムHTTPヘッダー network?: 'cellular' | 'wifi-only'; // ネットワーク制限 priority?: 'high' | 'normal' | 'low'; // ダウンロード優先度}イベントリスナー
Section titled “イベントリスナー”プラグインは包括的なイベント処理を提供します:
downloadProgress- リアルタイムのダウンロード進行状況を追跡downloadCompleted- ダウンロードの正常完了を処理downloadFailed- ダウンロードエラーと失敗を処理
ネットワーク設定
Section titled “ネットワーク設定”WiFi専用ダウンロード
Section titled “WiFi専用ダウンロード”await CapacitorDownloader.download({ id: 'large-file', url: 'https://example.com/video.mp4', destination: '/downloads/video.mp4', network: 'wifi-only' // WiFiネットワークのみに制限});// 高優先度ダウンロードawait CapacitorDownloader.download({ id: 'urgent-update', url: 'https://example.com/update.zip', destination: '/downloads/update.zip', priority: 'high'});ダウンロードステータス
Section titled “ダウンロードステータス”ダウンロードはさまざまなステータスを持つことができます:
- Pending: ダウンロード待機中
- Running: 現在ダウンロード中
- Paused: 一時停止中
- Completed: 正常に完了
- Failed: エラーが発生
- Stopped: 手動でキャンセル
ファイル情報
Section titled “ファイル情報”// ファイルの詳細を取得const fileInfo = await CapacitorDownloader.getFileInfo('/downloads/my-file.pdf');console.log('File size:', fileInfo.size);console.log('Last modified:', fileInfo.lastModified);console.log('MIME type:', fileInfo.mimeType);ベストプラクティス
Section titled “ベストプラクティス”- 競合を避けるために一意のダウンロードIDを使用する
- ネットワーク障害に対して適切なエラー処理を実装する
- 大きなダウンロードを開始する前にストレージスペースを考慮する
- モバイルデータを節約するために大きなファイルにはWiFi専用モードを使用する
- ストレージを管理するために完了したダウンロードをクリーンアップする