Skip to content
This repository was archived by the owner on Nov 24, 2017. It is now read-only.

plrthink/react-native-file-download

Folders and files

NameName
Last commit message
Last commit date

Latest commit

1bbd188 · Jun 14, 2016

History

30 Commits
May 10, 2016
Oct 9, 2015
Feb 25, 2016
Oct 9, 2015
Jun 14, 2016
Aug 31, 2015
May 10, 2016
Apr 2, 2016
Apr 2, 2016
May 29, 2016
May 29, 2016

Repository files navigation

This repo is deprecated in favor of react-native-fs

React Native File Download react-native-file-download npm version

Native file download utility for react-native

Note that does not support Android.

Installation

npm install react-native-file-download --save

Getting started - iOS

  1. In Xcode, in the project navigator right click LibrariesAdd Files to [your project's name]
  2. Go to node_modulesreact-native-file-download and add RNFileDownload.xcodeproj
  3. Add libRNFileDownload.a (from 'Products' under RNFileDownload.xcodeproj) to your project's Build PhasesLink Binary With Libraries phase
  4. Look for Header Search Paths and make sure it contains both $(SRCROOT)/../react-native/React and $(SRCROOT)/../../React - mark both as recursive
  5. Run your project (CMD+R)

Usage

require it in your file

const FileDownload = require('react-native-file-download')

you may also want to use something like react-native-fs to access the file system (check its repo for more information)

const RNFS = require('react-native-fs')

API

download(source: string, target: string): Promise

download file from source to target

Example

const URL = '/path/to/remote/file'
const DEST = RNFS.DocumentDirectoryPath
const fileName = 'zip.zip'
const headers = {
  'Accept-Language': 'en-US'
}

FileDownload.download(URL, DEST, fileName, headers)
.then((response) => {
  console.log(`downloaded! file saved to: ${response}`)
})
.catch((error) => {
  console.log(error)
})

addListener(source: string, callback: function): EmitterSubscription

event listener for progress of download

Example

const URL = '/path/to/remote/file'
const DEST = RNFS.DocumentDirectoryPath
const fileName = 'zip.zip'
const headers = {
  'Accept-Language': 'en-US'
}

FileDownload.addListener(URL, (info) => {
  console.log(`complete ${(info.totalBytesWritten / info.totalBytesExpectedToWrite * 100)}%`);
});

FileDownload.download(URL, DEST, fileName, headers)
.then((response) => {
  console.log(`downloaded! file saved to: ${response}`)
})
.catch((error) => {
  console.log(error)
})

About

[DEPRECATED] Native file download utility for react-native

Resources

License

Stars

Watchers

Forks

Packages

No packages published