1.0.4 • Published 2 months ago
pdf-excel-downloader v1.0.4
react-native-pdf-excel-file-downloader
react-native-pdf-excel-file-downloader is a React Native utility component designed for easy file downloading across iOS and Android platforms.
Features
- 📂 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.
Installation
## npm i pdf-excel-downloader react-native-blob-util
## npm i pdf-excel-downloader react-native-blob-util --force
iOS Configuration
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'
Android Configuration
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"/>
Basic Usage
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;
Example Callbacks
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.
API
Props
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). |
License
MIT License.