Skip to content
This repository was archived by the owner on Mar 16, 2019. It is now read-only.

Commit 9a12777

Browse files
committed
Update readme
1 parent 70fcb28 commit 9a12777

File tree

2 files changed

+57
-22
lines changed

2 files changed

+57
-22
lines changed

README.md

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# react-native-fetch-blob [![npm version](https://img.shields.io/badge/npm package-0.5.1-brightgreen.svg)](https://badge.fury.io/js/react-native-fetch-blob) ![](https://img.shields.io/badge/PR-Welcome-brightgreen.svg) ![](https://img.shields.io/badge/in progress-0.5.2-yellow.svg)
1+
# react-native-fetch-blob [![npm version](https://img.shields.io/badge/npm package-0.5.2-brightgreen.svg)](https://badge.fury.io/js/react-native-fetch-blob) ![](https://img.shields.io/badge/PR-Welcome-brightgreen.svg) ![](https://img.shields.io/badge/in progress-0.6.0-yellow.svg)
22

33
A module provides upload, download, and files access API. Supports file stream read/write for process large files.
44

@@ -27,7 +27,7 @@ This update is `backward-compatible` generally you don't have to change existing
2727
* [File stream](#user-content-file-stream)
2828
* [Manage cached files](#user-content-manage-cached-files)
2929
* [API](#user-content-api)
30-
* [config](#user-content-config)
30+
* [config](#user-content-configoptionsrnfetchblobconfigfetch)
3131
* [fetch](#user-content-fetchmethod-url-headers-bodypromisefetchblobresponse)
3232
* [session](#user-content-sessionnamestringrnfetchblobsession)
3333
* [base64](#user-content-base64)
@@ -492,7 +492,7 @@ You can also grouping requests by using `session` API, and use `dispose` to remo
492492

493493
Config API was introduced in `v0.5.0` which provides some options for the `fetch` task.
494494

495-
see [RNFetchBlobConfig](#user-content-rnfetchblobconfig)
495+
see [RNFetchBlobConfig](#user-content-configoptionsrnfetchblobconfigfetch)
496496

497497
### `fetch(method, url, headers, body):Promise<FetchBlobResponse>`
498498

@@ -520,13 +520,18 @@ Register on progress event handler for a fetch request.
520520

521521
A function that triggers when there's data received/sent, first argument is the number of sent/received bytes, and second argument is expected total bytes number.
522522

523-
#### `wrap(path:string):string`
523+
### `wrap(path:string):string`
524524

525525
Simply prepend `RNFetchBlob-file://` to a path, this make the file path becomes recognizable to native `fetch` method.
526526

527-
#### `session(name:string):RNFetchBlobSession`
527+
### `session(name:string):RNFetchBlobSession`
528528

529-
TODO
529+
Session API helps managing cached files, the following code, will try to return an existing session object with the given `name`, if it does not exist, create one.
530+
531+
```js
532+
RNFetchBlob.session('mysession')
533+
```
534+
see [Class RNFetchBlobSession](#user-content-rnfetchblobsession) for usage.
530535

531536
### `base64`
532537

@@ -823,16 +828,23 @@ A `session` is an object that helps you manage files. It simply main a list of f
823828

824829
| Version | |
825830
|---|---|
831+
| 0.5.2 | Fix improper url params bug [#26](https://github.com/wkh237/react-native-fetch-blob/issues/26) and change IOS HTTP implementation from NSURLConnection to NSURLSession |
826832
| 0.5.0 | Upload/download with direct access to file storage, and also added file access APIs |
827833
| 0.4.2 | Supports upload/download progress |
828834
| 0.4.1 | Fixe upload form-data missing file extension problem on Android |
829835
| 0.4.0 | Add base-64 encode/decode library and API |
830836
| ~0.3.0 | Upload/Download octet-stream and form-data |
831837

832-
### TODOs
838+
### TODO
833839

834840
* Customizable Multipart MIME type
835841

842+
### In Progress (v0.6.0)
843+
844+
* Add `readFile` and `WriteFile` API to `fs`
845+
* Add file access API for direct access RNFetchBlobResponse when the response is a file path
846+
* Android Download Manager file download API
847+
836848
### Development
837849

838850
If you're interested in hacking this module, check our [development guide](https://github.com/wkh237/react-native-fetch-blob/wiki/Development-Guide), there might be some helpful information.

src/README.md

Lines changed: 38 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
# react-native-fetch-blob [![npm version](https://badge.fury.io/js/react-native-fetch-blob.svg)](https://badge.fury.io/js/react-native-fetch-blob) ![](https://img.shields.io/badge/PR-Welcome-brightgreen.svg)
2-
3-
For latest document please visit our [github](https://github.com/wkh237/react-native-fetch-blob/)
1+
# react-native-fetch-blob [![npm version](https://img.shields.io/badge/npm package-0.5.2-brightgreen.svg)](https://badge.fury.io/js/react-native-fetch-blob) ![](https://img.shields.io/badge/PR-Welcome-brightgreen.svg) ![](https://img.shields.io/badge/in progress-0.6.0-yellow.svg)
42

53
A module provides upload, download, and files access API. Supports file stream read/write for process large files.
64

5+
**[Please visit our Github for updated document](https://github.com/wkh237/react-native-fetch-blob)**
6+
77
**Why do we need this**
88

99
At this moment, React Native does not support `Blob` object yet, so if you're going to send/receive binary data via `fetch` API, that might not work as you expect. See [[fetch] Does fetch with blob() marshal data across the bridge?](https://github.com/facebook/react-native/issues/854).
1010

11-
Hence you may getting into trouble in some use cases. For example, displaying an image on image server but the server requires a specific field(such as "Authorization") in headers or body, so you can't just pass the image uri to `Image` component because that will probably returns a 401 response. With help of this module, you can send a HTTP request with any headers, and decide how to handle the response/reqeust data. It can be just simply converted into BASE64 string, or store to a file directly so that you can read it by file stream or use it's path.
11+
Hence you may getting into trouble in some use cases. For example, displaying an image on image server but the server requires a specific field(such as "Authorization") in headers or body, so you can't just pass the image uri to `Image` component because that will probably returns a 401 response. With help of this module, you can send a HTTP request with any headers, and decide how to handle the response/reqeust data. The response data can be just simply converted into BASE64 string, or store to a file directly so that you can read it by file stream or use it's path.
1212

1313
This module is designed to be a substitution of `blob`, there's a set of file access API including basic CRUD method, and file stream reader/writer. Also it has a special `fetch` implementation that supports binary request/response body.
1414

@@ -29,7 +29,7 @@ This update is `backward-compatible` generally you don't have to change existing
2929
* [File stream](#user-content-file-stream)
3030
* [Manage cached files](#user-content-manage-cached-files)
3131
* [API](#user-content-api)
32-
* [config](#user-content-config)
32+
* [config](#user-content-configoptionsrnfetchblobconfigfetch)
3333
* [fetch](#user-content-fetchmethod-url-headers-bodypromisefetchblobresponse)
3434
* [session](#user-content-sessionnamestringrnfetchblobsession)
3535
* [base64](#user-content-base64)
@@ -50,9 +50,11 @@ Link package using [rnpm](https://github.com/rnpm/rnpm)
5050
rnpm link
5151
```
5252

53-
**Android Access Permission to External storage (Optional)**
53+
**Grant Permission to External storage for Android 5.0 or lower**
54+
55+
Mechanism about granting Android permissions has slightly different since Android 6.0 released, please refer to [Officail Document](https://developer.android.com/training/permissions/requesting.html).
5456

55-
If you're going to access external storage (say, SD card storage), you might have to add the following line to `AndroidManifetst.xml`.
57+
If you're going to access external storage (say, SD card storage) for `Android 5.0` (or lower) devices, you might have to add the following line to `AndroidManifetst.xml`.
5658

5759
```diff
5860
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
@@ -69,6 +71,10 @@ If you're going to access external storage (say, SD card storage), you might hav
6971

7072
```
7173

74+
**Grant Access Permission for Android 6.0**
75+
76+
Beginning in Android 6.0 (API level 23), users grant permissions to apps while the app is running, not when they install the app. So adding permissions in `AndroidManifest.xml` won't work in Android 6.0 devices. To grant permissions in runtime, you might use modules like [react-native-android-permissions](https://github.com/lucasferreira/react-native-android-permissions).
77+
7278
## Guide
7379

7480
```js
@@ -207,7 +213,8 @@ RNFetchBlob.fetch('POST', 'https://content.dropboxapi.com/2/files/upload', {
207213
mute : false
208214
}),
209215
'Content-Type' : 'application/octet-stream',
210-
// Change BASE64 encoded data to a file path with prefix `RNFetchBlob-file://` when the data comes from a file.
216+
// Change BASE64 encoded data to a file path with prefix `RNFetchBlob-file://`.
217+
// Or simply wrap the file path with RNFetchBlob.wrap().
211218
}, RNFetchBlob.wrap(PATH_TO_THE_FILE))
212219
.then((res) => {
213220
console.log(res.text())
@@ -259,7 +266,8 @@ What if you want to upload a file in some field ? Just like [upload a file from
259266
{
260267
name : 'avatar',
261268
filename : 'avatar.png',
262-
// Change BASE64 encoded data to a file path with prefix `RNFetchBlob-file://` when the data comes from a file path
269+
// Change BASE64 encoded data to a file path with prefix `RNFetchBlob-file://`.
270+
// Or simply wrap the file path with RNFetchBlob.wrap().
263271
data: RNFetchBlob.wrap(PATH_TO_THE_FILE)
264272
},
265273
// elements without property `filename` will be sent as plain text
@@ -325,7 +333,7 @@ If mime is null or undefined, then the mime type will be inferred from the file
325333
<img src="img/android-notification2.png" width="256">
326334

327335

328-
If you want to download notification or make the stored file visible like the above. You have to add some options to `config`.
336+
If you want to display a notification when file's completely download to storage (as the above), or make the downloaded file visible in "Downloads" app. You have to add some options to `config`.
329337

330338
```js
331339
RNFetchBlob.config({
@@ -486,7 +494,7 @@ You can also grouping requests by using `session` API, and use `dispose` to remo
486494

487495
Config API was introduced in `v0.5.0` which provides some options for the `fetch` task.
488496

489-
see [RNFetchBlobConfig](#user-content-rnfetchblobconfig)
497+
see [RNFetchBlobConfig](#user-content-configoptionsrnfetchblobconfigfetch)
490498

491499
### `fetch(method, url, headers, body):Promise<FetchBlobResponse>`
492500

@@ -514,9 +522,18 @@ Register on progress event handler for a fetch request.
514522

515523
A function that triggers when there's data received/sent, first argument is the number of sent/received bytes, and second argument is expected total bytes number.
516524

517-
#### `session(name:string):RNFetchBlobSession`
525+
### `wrap(path:string):string`
526+
527+
Simply prepend `RNFetchBlob-file://` to a path, this make the file path becomes recognizable to native `fetch` method.
518528

519-
TODO
529+
### `session(name:string):RNFetchBlobSession`
530+
531+
Session API helps managing cached files, the following code, will try to return an existing session object with the given `name`, if it does not exist, create one.
532+
533+
```js
534+
RNFetchBlob.session('mysession')
535+
```
536+
see [Class RNFetchBlobSession](#user-content-rnfetchblobsession) for usage.
520537

521538
### `base64`
522539

@@ -813,16 +830,22 @@ A `session` is an object that helps you manage files. It simply main a list of f
813830

814831
| Version | |
815832
|---|---|
833+
| 0.5.2 | Fix improper url params bug [#26](https://github.com/wkh237/react-native-fetch-blob/issues/26) and change IOS HTTP implementation from NSURLConnection to NSURLSession |
816834
| 0.5.0 | Upload/download with direct access to file storage, and also added file access APIs |
817835
| 0.4.2 | Supports upload/download progress |
818836
| 0.4.1 | Fixe upload form-data missing file extension problem on Android |
819837
| 0.4.0 | Add base-64 encode/decode library and API |
820838
| ~0.3.0 | Upload/Download octet-stream and form-data |
821839

822-
### TODOs
840+
### TODO
823841

824842
* Customizable Multipart MIME type
825-
* Improvement of file cache management API
843+
844+
### In Progress (v0.6.0)
845+
846+
* Add `readFile` and `WriteFile` API to `fs`
847+
* Add file access API for direct access RNFetchBlobResponse when the response is a file path
848+
* Android Download Manager file download API
826849

827850
### Development
828851

0 commit comments

Comments
 (0)