
Security News
Vite Releases Technical Preview of Rolldown-Vite, a Rust-Based Bundler
Vite releases Rolldown-Vite, a Rust-based bundler preview offering faster builds and lower memory usage as a drop-in replacement for Vite.
react-native-du
Advanced tools
A file download utility for react native
npm install react-native-du
or
yarn add react-native-du
import * as React from 'react';
import { StyleSheet, View, Button } from 'react-native';
import {
downloadFile,
downloadStatus,
DOWNLOAD_MANAGER_STATUS,
} from 'react-native-du';
export default function App() {
const downloadPdf = async () => {
try {
const id = await downloadFile({
url: 'https://cdn.pixabay.com/photo/2017/11/09/21/41/cat-2934720_1280.jpg',
fileName: 'cat.jpg',
desc: 'This is a cat ',
});
console.log({ id });
const status = await downloadStatus(id?.[0] || '');
const idx: string = status?.[0] || '';
console.log({ status: DOWNLOAD_MANAGER_STATUS[idx] });
} catch (err) {
console.log(err);
}
};
return (
<View style={styles.container}>
<Button title="Download" onPress={downloadPdf} />
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
},
box: {
width: 60,
height: 60,
marginVertical: 20,
},
});
async function downloadFile({
url,
fileName,
desc = '',
onPermissionDenied,
onError,
})
// params
{
url : 'https://cdn.pixabay.com/photo/2017/11/09/21/41/cat-2934720_1280.jpg' // request url,
fileName: 'cat.jpg' // file Name with extension
desc: 'Description of download manager' // optional
onPermissionDenied: ()=>{} // optional , this function gets called if storgae permission is denied
onError: (error)=>{} // optional , this function gets called if any exception is thrown
}
// returns
['downloadId'] or undefined
async function downloadStatus(downloadId: string)
// params
{
downloadId : 'id' // download id returned by downloadFile function,
}
// returns
['download_manager_status'] or undefined
You might have to add following permission in AndroidManifest.xml
file
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
See the contributing guide to learn how to contribute to the repository and the development workflow.
MIT
Made with create-react-native-library
FAQs
A file download utility for react native
The npm package react-native-du receives a total of 0 weekly downloads. As such, react-native-du popularity was classified as not popular.
We found that react-native-du demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Vite releases Rolldown-Vite, a Rust-based bundler preview offering faster builds and lower memory usage as a drop-in replacement for Vite.
Research
Security News
A malicious npm typosquat uses remote commands to silently delete entire project directories after a single mistyped install.
Research
Security News
Malicious PyPI package semantic-types steals Solana private keys via transitive dependency installs using monkey patching and blockchain exfiltration.