In this repo you will find quick snippet for downloading file in React Native (android & iOS)
Install rn-fetch-blob
in your project
npm i rn-fetch-blob
yarn add rn-fetch-blob
Add required permission in AndroidManifest.xml
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.DOWNLOAD_WITHOUT_NOTIFICATION" />
No changes required for iOS.
Copy DownloadFileServices.ts
File into your project & import like below.
// import File in your code π
import { DownloadFile } from "../DownloadFileServices";
function App() {
return (
<TouchableOpacity
onPress={() => {
let fileUrl = "Your File URL";
DownloadFile(fileUrl); // Pass URL in function
}}
>
<Text>Click Me</Text>
</TouchableOpacity>
);
}
Clone the project
git clone https://github.com/girish54321/ReactNativeDownloadDemo.git
Go to the project directory
cd ReactNativeDownloadDemo
Install dependencies
yarn
Start the project
yarn android_dev_debug
Just rename DownloadFileServices.ts
to DownloadFileServices.js
and remove types
. π
Contributions are always welcome!