Skip to content

Download file from URL and save it in Download (Android) or Documents (ios)

License

Notifications You must be signed in to change notification settings

omnilog/react-native-file-downloader

Repository files navigation

react-native-file-downloader

Boring to try to use rn-fetch-blob or the fork react-native-fetch-blob or another fork

This module provide a simple way to download file from API to Download (Android) / Documents(iOS)

npm downloads platform - android platform - ios

Installation

$ yarn add rn-file-downloader

Permissions

Android

Add this permissions in AndroidManifest.xml

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

iOS

Add this permissions in Info.plist

<key>UIFileSharingEnabled</key>
<true/>
<key>LSSupportsOpeningDocumentsInPlace</key>
<true/>

Usage

Methods

Name Description Arguments Return value
downloadFile Download a file in Download/Document url: string, filename: string, headers: stringify storePath: string

Sample

import { downloadFile } from "rn-file-downloader";

//...

downloadFile(
        'https://picsum.photos/200/300',
        'my-picture.jpg',
        JSON.stringify({
            Authorization: 'Bearer ' + accessToken,
        })
    )
    .then((path: string) => {
        //...
    })
    .catch((error: string) => {
        //...
    });

About

Download file from URL and save it in Download (Android) or Documents (ios)

Resources

License

Stars

Watchers

Forks

Packages

No packages published