Native file download utility for react-native
Note that does not support Android.
*Breaking change -- Now supports React Native v25+. Not compatible with prior versions. You can continue using older versions of React Native with react-native-file-download@0.0.9. *
Installation
npm install react-native-file-download --save
Getting started - iOS
- In XCode, in the project navigator right click
Libraries
➜Add Files to [your project's name]
- Go to
node_modules
➜react-native-file-download
and addRNFileDownload.xcodeproj
- Add
libRNFileDownload.a
(from 'Products' under RNFileDownload.xcodeproj) to your project'sBuild Phases
➜Link Binary With Libraries
phase - Look for Header Search Paths and make sure it contains both
$(SRCROOT)/../react-native/React
and$(SRCROOT)/../../React
- mark both as recursive - Run your project (
Cmd+R
)
Usage
require it in your file
const FileDownload =
you may also want to use something like react-native-fs to access the file system (check its repo for more information)
const RNFS =
API
download(source: string, target: string): Promise
download file from source to target
Example
const URL = '/path/to/remote/file'const DEST = RNFSDocumentDirectoryPathconst fileName = 'zip.zip'const headers = 'Accept-Language': 'en-US' FileDownload
addListener(source: string, callback: function): EmitterSubscription
event listener for progress of download
Example
const URL = '/path/to/remote/file'const DEST = RNFSDocumentDirectoryPathconst fileName = 'zip.zip'const headers = 'Accept-Language': 'en-US' FileDownload; FileDownload