Erste Schritte
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/de/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.
Installation
Section titled “Installation”npm install @capgo/capacitor-downloadernpx cap syncyarn add @capgo/capacitor-downloadernpx cap syncpnpm add @capgo/capacitor-downloadernpx cap syncbun add @capgo/capacitor-downloadernpx cap syncVerwendungsbeispiel
Section titled “Verwendungsbeispiel”import { CapacitorDownloader } from '@capgo/capacitor-downloader';
// Einen Download startenconst 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'});
// Auf Fortschritts-Updates hörenCapacitorDownloader.addListener('downloadProgress', (data) => { console.log(`Download ${data.id}: ${data.progress}% abgeschlossen`); console.log(`Heruntergeladen: ${data.bytesDownloaded}/${data.totalBytes} Bytes`);});
// Abschluss behandelnCapacitorDownloader.addListener('downloadCompleted', (data) => { console.log(`Download abgeschlossen: ${data.id}`); console.log(`Datei gespeichert in: ${data.path}`);});
// Fehler behandelnCapacitorDownloader.addListener('downloadFailed', (error) => { console.error(`Download fehlgeschlagen: ${error.id}`, error.message);});
// Einen Download pausierenawait CapacitorDownloader.pause(downloadId);
// Den Download fortsetzenawait CapacitorDownloader.resume(downloadId);
// Download-Status prüfenconst status = await CapacitorDownloader.checkStatus(downloadId);console.log('Download-Status:', status);
// Den Download stoppenawait CapacitorDownloader.stop(downloadId);Kern-API-Methoden
Section titled “Kern-API-Methoden”Download-Verwaltung
Section titled “Download-Verwaltung”download(options)- Neuen Datei-Download startenpause(id)- Laufenden Download pausierenresume(id)- Pausierten Download fortsetzenstop(id)- Download stoppen und abbrechencheckStatus(id)- Aktuellen Download-Status abrufen
Dateioperationen
Section titled “Dateioperationen”getFileInfo(path)- Dateiinformationen und Metadaten abrufen
Download-Konfiguration
Section titled “Download-Konfiguration”interface DownloadOptions { id: string; // Eindeutige Download-Kennung url: string; // Download-Quell-URL destination: string; // Lokaler Speicherpfad headers?: Record<string, string>; // Benutzerdefinierte HTTP-Header network?: 'cellular' | 'wifi-only'; // Netzwerkbeschränkungen priority?: 'high' | 'normal' | 'low'; // Download-Priorität}Event-Listener
Section titled “Event-Listener”Das Plugin bietet umfassende Ereignisbehandlung:
downloadProgress- Echtzeit-Download-Fortschritt verfolgendownloadCompleted- Erfolgreichen Download-Abschluss behandelndownloadFailed- Download-Fehler und -Ausfälle behandeln
Netzwerkkonfiguration
Section titled “Netzwerkkonfiguration”Nur-WiFi-Downloads
Section titled “Nur-WiFi-Downloads”await CapacitorDownloader.download({ id: 'large-file', url: 'https://example.com/video.mp4', destination: '/downloads/video.mp4', network: 'wifi-only' // Beschränkt auf WiFi-Netzwerke});Prioritätsverwaltung
Section titled “Prioritätsverwaltung”// Download mit hoher Prioritätawait CapacitorDownloader.download({ id: 'urgent-update', url: 'https://example.com/update.zip', destination: '/downloads/update.zip', priority: 'high'});Download-Zustände
Section titled “Download-Zustände”Downloads können verschiedene Zustände haben:
- Pending: In Warteschlange für Download
- Running: Wird gerade heruntergeladen
- Paused: Vorübergehend gestoppt
- Completed: Erfolgreich abgeschlossen
- Failed: Fehler aufgetreten
- Stopped: Manuell abgebrochen
Dateiinformationen
Section titled “Dateiinformationen”// Dateidetails abrufenconst fileInfo = await CapacitorDownloader.getFileInfo('/downloads/my-file.pdf');console.log('Dateigröße:', fileInfo.size);console.log('Zuletzt geändert:', fileInfo.lastModified);console.log('MIME-Typ:', fileInfo.mimeType);Bewährte Methoden
Section titled “Bewährte Methoden”- Verwenden Sie eindeutige Download-IDs, um Konflikte zu vermeiden
- Implementieren Sie ordnungsgemäße Fehlerbehandlung für Netzwerkausfälle
- Berücksichtigen Sie Speicherplatz vor dem Starten großer Downloads
- Verwenden Sie den Nur-WiFi-Modus für große Dateien, um mobile Daten zu schonen
- Bereinigen Sie abgeschlossene Downloads, um Speicher zu verwalten