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
Android | IOS |
Just run
yarn add expo-downloads-manager
To see a full-code working example,you can check out this example app expo-download-manager-example.
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 ).
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.
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.
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:
Bug reports are also welcome, please provide a minimum reproducible example along with a bug report