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

Commit 1d206e7

Browse files
committed
Update README.md
1 parent 534fadc commit 1d206e7

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

README.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ A module provides upload, download, and files access API. Supports file stream r
66

77
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).
88

9-
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.
9+
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.
1010

1111
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.
1212

@@ -205,7 +205,8 @@ RNFetchBlob.fetch('POST', 'https://content.dropboxapi.com/2/files/upload', {
205205
mute : false
206206
}),
207207
'Content-Type' : 'application/octet-stream',
208-
// Change BASE64 encoded data to a file path with prefix `RNFetchBlob-file://` when the data comes from a file.
208+
// Change BASE64 encoded data to a file path with prefix `RNFetchBlob-file://`.
209+
// Or simply wrap the file path with RNFetchBlob.wrap().
209210
}, RNFetchBlob.wrap(PATH_TO_THE_FILE))
210211
.then((res) => {
211212
console.log(res.text())
@@ -257,7 +258,8 @@ What if you want to upload a file in some field ? Just like [upload a file from
257258
{
258259
name : 'avatar',
259260
filename : 'avatar.png',
260-
// Change BASE64 encoded data to a file path with prefix `RNFetchBlob-file://` when the data comes from a file path
261+
// Change BASE64 encoded data to a file path with prefix `RNFetchBlob-file://`.
262+
// Or simply wrap the file path with RNFetchBlob.wrap().
261263
data: RNFetchBlob.wrap(PATH_TO_THE_FILE)
262264
},
263265
// elements without property `filename` will be sent as plain text
@@ -512,6 +514,10 @@ Register on progress event handler for a fetch request.
512514

513515
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.
514516

517+
#### `wrap(path:string):string`
518+
519+
Simply prepend `RNFetchBlob-file://` to a path, this make the file path becomes recognizable to native `fetch` method.
520+
515521
#### `session(name:string):RNFetchBlobSession`
516522

517523
TODO

0 commit comments

Comments
 (0)