Browse Source

Update README.md

wkh237 8 years ago
parent
commit
1d206e7fa5
1 changed files with 9 additions and 3 deletions
  1. 9
    3
      README.md

+ 9
- 3
README.md View File

6
 
6
 
7
 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).
7
 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).
8
 
8
 
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.
10
 
10
 
11
 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.
11
 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.
12
 
12
 
205
       mute : false
205
       mute : false
206
     }),
206
     }),
207
     'Content-Type' : 'application/octet-stream',
207
     '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().
209
   }, RNFetchBlob.wrap(PATH_TO_THE_FILE))
210
   }, RNFetchBlob.wrap(PATH_TO_THE_FILE))
210
   .then((res) => {
211
   .then((res) => {
211
     console.log(res.text())
212
     console.log(res.text())
257
     {
258
     {
258
       name : 'avatar',
259
       name : 'avatar',
259
       filename : 'avatar.png',
260
       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().
261
       data: RNFetchBlob.wrap(PATH_TO_THE_FILE)
263
       data: RNFetchBlob.wrap(PATH_TO_THE_FILE)
262
     },
264
     },
263
     // elements without property `filename` will be sent as plain text
265
     // elements without property `filename` will be sent as plain text
512
 
514
 
513
 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.
515
 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.
514
 
516
 
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
+
515
 #### `session(name:string):RNFetchBlobSession`
521
 #### `session(name:string):RNFetchBlobSession`
516
 
522
 
517
 TODO
523
 TODO