Skip to content

A library that allows you to download files from links and view downloaded files from your app.

License

Notifications You must be signed in to change notification settings

thareekanvar/expo-downloads-manager

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

expo-download-manager

GitHub last commit npm version npm downloads weekly

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

Demo-Preview

Android IOS

Table of contents

Installation

(Back to top)

Just run

yarn add expo-downloads-manager

Usage

(Back to top)

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

(Back to top)

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

Adding new features or fixing bugs

(Back to top)

Bug reports are also welcome, please provide a minimum reproducible example along with a bug report

About

A library that allows you to download files from links and view downloaded files from your app.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published