expo-downloads-manager
Version:
download manager based on expo react native
158 lines (105 loc) • 4.42 kB
Markdown
<!-- omit in toc -->
<!-- Add buttons here -->



<!-- Describe your project in brief -->
A library that allows you to download files from links and view downloaded files from your app.
You need the following permissions to use this library
1. `CAMERA_ROLL / MEDIA_LIBRARY` permissions granted by the user
<table>
<tr>
<td>Android</td>
<td>IOS</td>
</tr>
<tr>
<td><img src="https://user-images.githubusercontent.com/26960181/155687226-a6199760-39b5-4fd1-8389-e087b12ce237.gif" width="250" height="450"></td>
<td><img src="https://user-images.githubusercontent.com/26960181/155687314-567066a2-2b96-4003-b740-9dbc698a64db.gif" width="250" height="450"></td>
</tr>
</table>
- [Table of contents](
- [Installation](
- [Usage](
- [downloadFileFromUri](
- [openDownloadedFile](
- [checkFileIsAvailable](
- [Contribute](
- [Sponsor](
- [PayPal](
- [Adding new features or fixing bugs](
[(Back to top)](
Just run
```
yarn add expo-downloads-manager
```
[(Back to top)](
To see a full-code working example,you can check out this example app [expo-download-manager-example](https://github.com/thareekanvar/expo-download-manager-example).
```jsx
import { downloadFileFromUri } from 'expo-downloads-manager';
const callback = (downloadProgress) => {
const progress =
downloadProgress.totalBytesWritten /
downloadProgress.totalBytesExpectedToWrite;
setDownloadProgress(progress);
};
...
<Button title='Download' onPress={async () => {
const { status, error } = await downloadFileFromUri(
uri,
fileName,
callback
);
}}
```
Arguments:
- `uri`: `string` - the URI of the resource you want to download.
- `filename`: `string` - the filename to save the resource (only the filename, no path information, must be unique).
- `callback`?: `({totalBytesWritten: number, totalBytesExpectedToWrite: number}) => void` - Optional argument, gets called on every file write to the system with information about how much of the file has been written and how much is left to write.
This function will download a file from the given URI.
Return:
- `status`: `"downloading" | "finished" | "error"` - current status of the download.
- `error`: `string` - reason for the error ( error return only if there is any error occurs ).
### openDownloadedFile
```jsx
import { openDownloadedFile } from 'expo-downloads-manager';
...
<Button title='Download' onPress={async () => {
await openDownloadedFile(fileName)
}}
```
Arguments:
- `filename`: `string` - the filename used to save the resource to (only the filename, no path information, must be unique).
This function will open the downloaded file.
### checkFileIsAvailable
```jsx
import { checkFileIsAvailable } from 'expo-downloads-manager';
...
async function checkAvail() {
const { isAvailable } = await checkFileIsAvailable(fileName);
if (isAvailable) {
// type your code.
}
}
```
Arguments:
- `filename`: `string` - the filename used to save the resource to (only the filename, no path information, must be unique).
This function will check this file is already downloaded or not.
Return:
- `isAvailable`: `Boolean` - availability of the file.it returns true file is available else not.
# Contribute
### Sponsor
[(Back to top)](#table-of-contents)
If this saved you development time or you otherwise found it useful, leave a star or follow in GitHub.
You can also buy me a coffee to say thanks:
<!-- PayPal -->
#### PayPal
[](https://www.paypal.com/paypalme/thareekanvar)
### Adding new features or fixing bugs
[(Back to top)](#table-of-contents)
Bug reports are also welcome, please provide a minimum reproducible example along with a bug report