expo-downloads-manager
v1.0.2
Published
download manager based on expo react native
Downloads
113
Maintainers
Readme
expo-download-manager
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
CAMERA_ROLL / MEDIA_LIBRARY
permissions granted by the user
Demo-Preview
Table of contents
Installation
Just run
yarn add expo-downloads-manager
Usage
To see a full-code working example,you can check out this example app expo-download-manager-example.
downloadFileFromUri
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
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
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
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
Adding new features or fixing bugs
Bug reports are also welcome, please provide a minimum reproducible example along with a bug report