Memulai
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/id/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.
Instalasi
Section titled “Instalasi”npm install @capgo/capacitor-downloadernpx cap syncyarn add @capgo/capacitor-downloadernpx cap syncpnpm add @capgo/capacitor-downloadernpx cap syncbun add @capgo/capacitor-downloadernpx cap syncContoh Penggunaan
Section titled “Contoh Penggunaan”import { CapacitorDownloader } from '@capgo/capacitor-downloader';
// Start a downloadconst 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'});
// Listen for progress updatesCapacitorDownloader.addListener('downloadProgress', (data) => { console.log(`Download ${data.id}: ${data.progress}% complete`); console.log(`Downloaded: ${data.bytesDownloaded}/${data.totalBytes} bytes`);});
// Handle completionCapacitorDownloader.addListener('downloadCompleted', (data) => { console.log(`Download completed: ${data.id}`); console.log(`File saved to: ${data.path}`);});
// Handle errorsCapacitorDownloader.addListener('downloadFailed', (error) => { console.error(`Download failed: ${error.id}`, error.message);});
// Pause a downloadawait CapacitorDownloader.pause(downloadId);
// Resume the downloadawait CapacitorDownloader.resume(downloadId);
// Check download statusconst status = await CapacitorDownloader.checkStatus(downloadId);console.log('Download status:', status);
// Stop the downloadawait CapacitorDownloader.stop(downloadId);Metode API Inti
Section titled “Metode API Inti”Manajemen Download
Section titled “Manajemen Download”download(options)- Mulai download file barupause(id)- Jeda download yang sedang berlangsungresume(id)- Lanjutkan download yang dijedastop(id)- Hentikan dan batalkan downloadcheckStatus(id)- Dapatkan status download saat ini
Operasi File
Section titled “Operasi File”getFileInfo(path)- Ambil informasi dan metadata file
Konfigurasi Download
Section titled “Konfigurasi Download”interface DownloadOptions { id: string; // Unique download identifier url: string; // Download source URL destination: string; // Local save path headers?: Record<string, string>; // Custom HTTP headers network?: 'cellular' | 'wifi-only'; // Network restrictions priority?: 'high' | 'normal' | 'low'; // Download priority}Event Listener
Section titled “Event Listener”Plugin menyediakan penanganan event komprehensif:
downloadProgress- Lacak progress download real-timedownloadCompleted- Tangani penyelesaian download suksesdownloadFailed- Tangani error dan kegagalan download
Konfigurasi Network
Section titled “Konfigurasi Network”Download WiFi Saja
Section titled “Download WiFi Saja”await CapacitorDownloader.download({ id: 'large-file', url: 'https://example.com/video.mp4', destination: '/downloads/video.mp4', network: 'wifi-only' // Restricts to WiFi networks only});Manajemen Prioritas
Section titled “Manajemen Prioritas”// High priority downloadawait CapacitorDownloader.download({ id: 'urgent-update', url: 'https://example.com/update.zip', destination: '/downloads/update.zip', priority: 'high'});Status Download
Section titled “Status Download”Download dapat dalam berbagai status:
- Pending: Antri untuk download
- Running: Sedang mendownload
- Paused: Dihentikan sementara
- Completed: Berhasil selesai
- Failed: Mengalami error
- Stopped: Dibatalkan secara manual
Informasi File
Section titled “Informasi File”// Get file detailsconst 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);Praktik Terbaik
Section titled “Praktik Terbaik”- Gunakan ID download unik untuk menghindari konflik
- Implementasikan penanganan error yang tepat untuk kegagalan jaringan
- Pertimbangkan ruang penyimpanan sebelum memulai download besar
- Gunakan mode WiFi saja untuk file besar untuk menghemat data seluler
- Bersihkan download yang selesai untuk mengelola penyimpanan