Prise en main
Copiez un prompt de configuration incluant les étapes d'installation et le guide markdown complet pour ce 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/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.
Installer
Section intitulée « Installation »Vous pouvez utiliser notre configuration assistée par IA pour installer le plugin. Ajoutez les skills Capgo à votre outil d'IA avec la commande suivante :
npx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-pluginsUtilisez ensuite le prompt suivant :
Use the `capacitor-plugins` skill from `Cap-go/capgo-skills` to install the `@capgo/capacitor-downloader` plugin in my project.Si vous préférez une installation manuelle, installez le plugin en exécutant les commandes suivantes et suivez les instructions spécifiques à chaque plateforme ci-dessous :
bun add @capgo/capacitor-downloaderbunx cap syncImporter
Section intitulée « Import »import { CapacitorDownloader } from '@capgo/capacitor-downloader';Démarrage rapide
Section intitulée « Démarrage rapide »Téléchargez vers un dossier connu, écoutez la progression et reprenez après un redémarrage de l'app si c'est supporté.
import { CapacitorDownloader } from '@capgo/capacitor-downloader';
const progressListener = await CapacitorDownloader.addListener('downloadProgress', (event) => { if (event.id === 'offline-pack') { console.log(event.progress); }});
const task = await CapacitorDownloader.download({ id: 'offline-pack', url: 'https://cdn.example.com/large-pack.zip', destination: 'downloads/offline-pack.zip',});Exemple : pause et reprise
Section intitulée « Exemple : pause et reprise »await CapacitorDownloader.pause({ id: 'offline-pack' });await CapacitorDownloader.resume({ id: 'offline-pack' });Exemple : inspecter un fichier terminé
Section intitulée « Exemple : inspecter un fichier terminé »import { Capacitor } from '@capacitor/core';import { Directory, Filesystem } from '@capacitor/filesystem';
const relativePath = 'downloads/offline-pack.zip';const path = Capacitor.getPlatform() === 'ios' ? (await Filesystem.getUri({ directory: Directory.Documents, path: relativePath })).uri : relativePath;
const info = await CapacitorDownloader.getFileInfo({ path });Erreurs courantes
Section intitulée « Erreurs courantes »- Destination du stockage: choisissez un
destinationvotre application peut lire sur chaque plateforme. - Arrière-plan: les téléchargements s'exécutent en arrière-plan sur iOS et Android. Sur le Web,
download()n'est pas implémenté ; utilisez plutôt un flux de téléchargement via le navigateur. - Statut: utiliser
checkStatustant que le processus de l'application est actif. Sur iOS, les task IDs ne sont pas restaurés après un redémarrage.
Aperçu de API
Section intitulée « Aperçu API »download
Section intitulée « download »Démarrer une nouvelle tâche de téléchargement.
import { CapacitorDownloader } from '@capgo/capacitor-downloader';
const task = await CapacitorDownloader.download({ id: 'my-download', url: 'https://example.com/file.pdf', destination: 'downloads/file.pdf'});Mettre en pause un téléchargement en cours.\nLe téléchargement peut être repris plus tard à partir du même point.
import { CapacitorDownloader } from '@capgo/capacitor-downloader';
await CapacitorDownloader.pause({ id: 'id-123' });Reprendre un téléchargement en pause. Reprend là où il s'était arrêté.
import { CapacitorDownloader } from '@capgo/capacitor-downloader';
await CapacitorDownloader.resume({ id: 'id-123' });Arrêter et annuler un téléchargement définitivement. Les données téléchargées seront supprimées.
import { CapacitorDownloader } from '@capgo/capacitor-downloader';
await CapacitorDownloader.stop({ id: 'id-123' });checkStatus
Section intitulée « checkStatus »Vérifier le statut actuel d'un téléchargement.
import { CapacitorDownloader } from '@capgo/capacitor-downloader';
const result = await CapacitorDownloader.checkStatus({ id: 'id-123' });console.log(result);getFileInfo
Section intitulée « getFileInfo »Obtenir des informations sur un fichier téléchargé.
import { CapacitorDownloader } from '@capgo/capacitor-downloader';
const result = await CapacitorDownloader.getFileInfo({ path: 'path/to/file' });console.log(result);Référence de type
Section intitulée « Référence de type »DownloadOptions
Section intitulée « DownloadOptions »Options de configuration pour lancer un téléchargement.
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
Section intitulée « DownloadTask »Représente l'état actuel et la progression d'une tâche de téléchargement.
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';}Source de vérité
Section intitulée « Source de vérité »Cette page est générée à partir de src/definitions.ts. Relancez la synchronisation lorsque l’API public change en amont.
Continuer depuis Getting Started
Section intitulée « Continuer après Prise en main »Si vous utilisez Prise en main pour planifier les opérations du dashboard et de API, connectez-l’avec Utiliser @capgo/capacitor-downloader pour la capacité native dans Utiliser @capgo/capacitor-downloader, Aperçu de API pour les détails d'implémentation dans « Vue d'ensemble de API », Introduction pour les détails d'implémentation dans l'introduction, Clés API pour les détails d'implémentation dans « Clés API », et Appareils pour les détails d'implémentation dans Devices.