Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/plrthink/react-native-file-download
[DEPRECATED] Native file download utility for react-native
https://github.com/plrthink/react-native-file-download
Last synced: about 1 month ago
JSON representation
[DEPRECATED] Native file download utility for react-native
- Host: GitHub
- URL: https://github.com/plrthink/react-native-file-download
- Owner: plrthink
- License: mit
- Archived: true
- Created: 2015-08-31T05:29:22.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2016-06-14T05:56:31.000Z (over 8 years ago)
- Last Synced: 2024-08-16T18:56:40.485Z (5 months ago)
- Language: Objective-C
- Homepage:
- Size: 178 KB
- Stars: 47
- Watchers: 0
- Forks: 10
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-react-native - react-native-file-download ★45 - A simple file download module for react-native (Components / Backend)
- awesome-react-native - react-native-file-download ★45 - A simple file download module for react-native (Components / Backend)
- awesome-react-native - react-native-file-download ★45 - A simple file download module for react-native (Components / Backend)
- awesome-react-native-ui - react-native-file-download ★35 - A simple file download module for react-native (Components / Backend)
- awesome-react-native - react-native-file-download ★45 - A simple file download module for react-native (Components / Backend)
README
## This repo is deprecated in favor of [react-native-fs](https://github.com/johanneslumpe/react-native-fs#promise-downloadfileoptions)
# React Native File Download [![react-native-file-download](http://img.shields.io/npm/dm/react-native-file-download.svg)](https://www.npmjs.org/package/react-native-file-download) [![npm version](https://badge.fury.io/js/react-native-file-download.svg)](https://badge.fury.io/js/react-native-file-download)
> Native file download utility for react-native
##### *Note that does not support Android.*
## Installation
```bash
npm install react-native-file-download --save
```## Getting started - iOS
1. In Xcode, in the project navigator right click `Libraries` ➜ `Add Files to [your project's name]`
2. Go to `node_modules` ➜ `react-native-file-download` and add `RNFileDownload.xcodeproj`
3. Add `libRNFileDownload.a` (from 'Products' under RNFileDownload.xcodeproj) to your project's `Build Phases` ➜ `Link 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
```js
const FileDownload = require('react-native-file-download')
```you may also want to use something like [react-native-fs](https://github.com/johanneslumpe/react-native-fs) to access the file system (check its repo for more information)
```js
const RNFS = require('react-native-fs')
```## API
**download(source: string, target: string): Promise**
> download file from source to target
Example
```js
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
```js
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)
})
```