react-native-pdf-excel-file-downloader is a React Native utility component designed for easy file downloading across iOS and Android platforms.
- 📂 Download Files: Supports downloading files with various formats like PDF, Word, Excel, images, etc.
- 🖥️ Platform Support: Works on both Android and iOS.
- 🚀 Progress Tracking: Real-time download progress display.
- 🛠️ Customizable: Provides callbacks for download completion, error handling, and progress updates.
## npm i pdf-excel-downloader react-native-blob-util
## npm i pdf-excel-downloader react-native-blob-util --force
Add the following permissions to your Info.plist
file for iOS:
<key>NSPhotoLibraryUsageDescription</key>
<string>Permission to save downloaded files to your photo library.</string>
<key>NSDocumentDirectoryUsageDescription</key>
<string>Permission to save downloaded files to your document directory.</string>
<key>UIFileSharingEnabled</key> <true/> <key>LSSupportsOpeningDocumentsInPlace</key> <true/>
then run pod install or pod 'react-native-blob-util'
Ensure the following permissions are added to your AndroidManifest.xml
:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
Here is an example of how to integrate DownloadFileComponent
into your React Native project:
import React from 'react';
import { View, Button, Text } from 'react-native';
import {Downloader} from 'pdf-excel-downloader';
const Main = () => {
const fileUrl = 'https://morth.nic.in/sites/default/files/dd12-13_0.pdf'; // Replace with your file URL
const handleDownloadComplete = (filePath) => {
console.log('Download complete! File saved at:', filePath);
};
const handleError = (error) => {
console.error('Download failed:', error);
};
const handleProgress = (progress) => {
console.log(`Download progress: ${progress}%`);
};
const { downloadFile, downloading, downloadProgress } = Downloader({
fileUrl,
showProgress: true,
onDownloadComplete: handleDownloadComplete,
onError: handleError,
onProgress: handleProgress,
});
return (
<View>
<Button
title="Download File"
onPress={downloadFile}
disabled={downloading}
/>
{downloading && <Text>Progress: {downloadProgress}%</Text>}
</View>
);
};
export default Main;
-
onDownloadComplete(path)
: Invoked when the download finishes, providing the saved file's path. -
onError(error)
: Invoked if there’s an error during the download. -
onProgress(percentage)
: Updates the download progress percentage.
Prop | Type | Description |
---|---|---|
fileUrl |
String | he URL of the file to download. |
showProgress |
Boolean | Whether to display download progress or not. |
onDownloadComplete |
Function | Callback invoked when the download is complete. It receives the file path as a parameter. |
onError |
Function | Callback invoked if an error occurs during the download process. |
onProgress |
Function | Callback invoked during download to show progress (percentage). |
MIT License.