Background downloads
Continue downloads when app is backgrounded 📥
The Capacitor Downloader plugin provides powerful file download capabilities with support for background downloads, progress tracking, and comprehensive download management. This plugin enables robust file downloading with pause/resume functionality and detailed progress monitoring.
⚠️ Work in Progress: This plugin is currently under development and not yet ready for production use.
Background downloads
Continue downloads when app is backgrounded 📥
Progress tracking
Real-time download progress and status monitoring 📊
Download control
Pause, resume, and stop downloads dynamically ⏯️
Network options
Configure network preferences and priorities 📶
npm install @capgo/capacitor-downloadernpx cap sync
download(options)
- Start a new file downloadpause(id)
- Pause an ongoing downloadresume(id)
- Resume a paused downloadstop(id)
- Stop and cancel a downloadcheckStatus(id)
- Get current download statusgetFileInfo(path)
- Retrieve file information and metadatainterface 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}
The plugin provides comprehensive event handling:
downloadProgress
- Track real-time download progressdownloadCompleted
- Handle successful download completiondownloadFailed
- Handle download errors and failuresimport { Downloader } from '@capgo/capacitor-downloader';
// Start a downloadconst downloadId = 'my-download-001';await Downloader.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 updatesDownloader.addListener('downloadProgress', (data) => { console.log(`Download ${data.id}: ${data.progress}% complete`); console.log(`Downloaded: ${data.bytesDownloaded}/${data.totalBytes} bytes`);});
// Handle completionDownloader.addListener('downloadCompleted', (data) => { console.log(`Download completed: ${data.id}`); console.log(`File saved to: ${data.path}`);});
// Handle errorsDownloader.addListener('downloadFailed', (error) => { console.error(`Download failed: ${error.id}`, error.message);});
// Pause a downloadawait Downloader.pause(downloadId);
// Resume the downloadawait Downloader.resume(downloadId);
// Check download statusconst status = await Downloader.checkStatus(downloadId);console.log('Download status:', status);
// Stop the downloadawait Downloader.stop(downloadId);
await Downloader.download({ id: 'large-file', url: 'https://example.com/video.mp4', destination: '/downloads/video.mp4', network: 'wifi-only' // Restricts to WiFi networks only});
// High priority downloadawait Downloader.download({ id: 'urgent-update', url: 'https://example.com/update.zip', destination: '/downloads/update.zip', priority: 'high'});
Downloads can be in various states:
// Get file detailsconst fileInfo = await Downloader.getFileInfo('/downloads/my-file.pdf');console.log('File size:', fileInfo.size);console.log('Last modified:', fileInfo.lastModified);console.log('MIME type:', fileInfo.mimeType);
This plugin is inspired by react-native-background-downloader and is currently being developed. Features may change as development progresses.
Check the complete documentation for detailed implementation guides when the plugin reaches production readiness.