To Download an Image
const { config, fs } = RNFetchBlob;
let PictureDir = fs.dirs.PictureDir;
let options = {
fileCache: true,
addAndroidDownloads: {
//Related to the Android only
useDownloadManager: true,
notification: true,
path:
PictureDir +
'/image_' +
Math.floor(date.getTime() +
date.getSeconds() / 2) + ext,
description: 'Image',
},
};
config(options)
.fetch('GET', image_URL)
.then(res => {
//Showing alert after successful downloading
console.log('res -> ', JSON.stringify(res));
alert('Image Downloaded Successfully.');
});
To Make a React Native App
npm install -g react-native-cli
Run the following commands to create a new React Native project
react-native init ProjectName
Installation of Dependency
cd ProjectName
and run the following command
npm install rn-fetch-blob --save
Android Permission to Access Contact List
In this example, we are going to store the downloaded file in the external storage and to do that we have to add permission into the AndroidManifest.xml
file. Please add the following permissions in your AndroidMnifest.xml.
Go to YourProject -> android -> app -> main -> AndroidMnifest.xml
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
/>
Code to Download Image in React Native
Please comment , have any query
Thanks..