|
@@ -11,7 +11,7 @@ A project committed to make file acess and data transfer easier, efficient for R
|
11
|
11
|
- File stream support for dealing with large file
|
12
|
12
|
- Blob, File, XMLHttpRequest polyfills that make browser-based library available in RN (experimental)
|
13
|
13
|
|
14
|
|
-> The npm package is inside `src` folder, this is development folder
|
|
14
|
+> The npm package is inside `src` folder, if you're going to install via git repository do not directly poiint to this folder
|
15
|
15
|
|
16
|
16
|
## TOC
|
17
|
17
|
* [About](#user-content-about)
|
|
@@ -140,11 +140,10 @@ If you're using ES5 require statement to load the module, please add `default`.
|
140
|
140
|
var RNFetchBlob = require('react-native-fetch-blob').default
|
141
|
141
|
```
|
142
|
142
|
|
143
|
|
-### HTTP Data Transfer
|
|
143
|
+## HTTP Data Transfer
|
144
|
144
|
|
145
|
|
----
|
146
|
145
|
|
147
|
|
-#### Regular Request
|
|
146
|
+### Regular Request
|
148
|
147
|
|
149
|
148
|
After `0.8.0` react-native-fetch-blob automatically decide how to send the body by checking its type and `Content-Type` in header. The rule is described in the following diagram
|
150
|
149
|
|
|
@@ -160,7 +159,7 @@ To sum up :
|
160
|
159
|
|
161
|
160
|
> After 0.9.4, we disabled `Chunked` transfer encoding by default, if you're going to use it, you should explicitly set header `Transfer-Encoding` to `Chunked`.
|
162
|
161
|
|
163
|
|
-#### Download example : Fetch files that needs authorization token
|
|
162
|
+### Download example : Fetch files that needs authorization token
|
164
|
163
|
|
165
|
164
|
Most simple way is download to memory and stored as BASE64 encoded string, this is handy when the response data is small.
|
166
|
165
|
|
|
@@ -186,7 +185,7 @@ RNFetchBlob.fetch('GET', 'http://www.example.com/images/img1.png', {
|
186
|
185
|
})
|
187
|
186
|
```
|
188
|
187
|
|
189
|
|
-#### Download to storage directly
|
|
188
|
+### Download to storage directly
|
190
|
189
|
|
191
|
190
|
If the response data is large, that would be a bad idea to convert it into BASE64 string. A better solution is streaming the response directly into a file, simply add a `fileCache` option to config, and set it to `true`. This will make incoming response data stored in a temporary path **without** any file extension.
|
192
|
191
|
|
|
@@ -280,7 +279,7 @@ RNFetchBlob.fetch('POST', 'https://content.dropboxapi.com/2/files/upload', {
|
280
|
279
|
})
|
281
|
280
|
```
|
282
|
281
|
|
283
|
|
-#### Upload a file from storage
|
|
282
|
+### Upload a file from storage
|
284
|
283
|
|
285
|
284
|
If you're going to use a `file` as request body, just wrap the path with `wrap` API.
|
286
|
285
|
|
|
@@ -306,7 +305,7 @@ RNFetchBlob.fetch('POST', 'https://content.dropboxapi.com/2/files/upload', {
|
306
|
305
|
})
|
307
|
306
|
```
|
308
|
307
|
|
309
|
|
-#### Multipart/form-data example : Post form data with file and data
|
|
308
|
+### Multipart/form-data example : Post form data with file and data
|
310
|
309
|
|
311
|
310
|
In `version >= 0.3.0` you can also post files with form data, just put an array in `body`, with elements have property `name`, `data`, and `filename`(optional).
|
312
|
311
|
|
|
@@ -377,7 +376,7 @@ What if you want to append a file to form data ? Just like [upload a file from s
|
377
|
376
|
})
|
378
|
377
|
```
|
379
|
378
|
|
380
|
|
-#### Upload/Download progress
|
|
379
|
+### Upload/Download progress
|
381
|
380
|
|
382
|
381
|
In `version >= 0.4.2` it is possible to know the upload/download progress. After `0.7.0` IOS and Android upload progress are also supported.
|
383
|
382
|
|
|
@@ -402,7 +401,7 @@ In `version >= 0.4.2` it is possible to know the upload/download progress. After
|
402
|
401
|
})
|
403
|
402
|
```
|
404
|
403
|
|
405
|
|
-#### Cancel Request
|
|
404
|
+### Cancel Request
|
406
|
405
|
|
407
|
406
|
After `0.7.0` it is possible to cancel a HTTP request. When the request cancel, it will definately throws an promise rejection, be sure to catch it.
|
408
|
407
|
|
|
@@ -541,9 +540,9 @@ Or show an image in image viewer
|
541
|
540
|
android.actionViewIntent(PATH_OF_IMG, 'image/png')
|
542
|
541
|
```
|
543
|
542
|
|
544
|
|
-### File System
|
|
543
|
+## File System
|
545
|
544
|
|
546
|
|
-#### File Access
|
|
545
|
+### File Access
|
547
|
546
|
|
548
|
547
|
File access APIs were made when developing `v0.5.0`, which helping us write tests, and was not planned to be a part of this module. However we realized that, it's hard to find a great solution to manage cached files, every one who use this moudle may need these APIs for there cases.
|
549
|
548
|
|
|
@@ -571,7 +570,7 @@ File Access APIs
|
571
|
570
|
|
572
|
571
|
See [File API](https://github.com/wkh237/react-native-fetch-blob/wiki/File-System-Access-API) for more information
|
573
|
572
|
|
574
|
|
-#### File Stream
|
|
573
|
+### File Stream
|
575
|
574
|
|
576
|
575
|
In `v0.5.0` we've added `writeStream` and `readStream`, which allows your app read/write data from file path. This API creates a file stream, rather than convert whole data into BASE64 encoded string, it's handy when processing **large files**.
|
577
|
576
|
|
|
@@ -620,7 +619,7 @@ RNFetchBlob.fs.writeStream(
|
620
|
619
|
|
621
|
620
|
```
|
622
|
621
|
|
623
|
|
-#### Cache File Management
|
|
622
|
+### Cache File Management
|
624
|
623
|
|
625
|
624
|
When using `fileCache` or `path` options along with `fetch` API, response data will automatically stored into file system. The files will **NOT** removed unless you `unlink` it. There're several ways to remove the files
|
626
|
625
|
|
|
@@ -677,7 +676,7 @@ You can also grouping requests by using `session` API, and use `dispose` to remo
|
677
|
676
|
|
678
|
677
|
```
|
679
|
678
|
|
680
|
|
-#### Transfer Encoding
|
|
679
|
+### Transfer Encoding
|
681
|
680
|
|
682
|
681
|
After `0.9.4`, the `Chunked` transfer encoding is disabled by default due to some service provoder may not support chunked transfer. To enable it, set `Transfer-Encoding` header to `Chunked`.
|
683
|
682
|
|
|
@@ -685,7 +684,7 @@ After `0.9.4`, the `Chunked` transfer encoding is disabled by default due to som
|
685
|
684
|
RNFetchBlob.fetch('POST', 'http://example.com/upload', { 'Transfer-Encoding' : 'Chunked' }, bodyData)
|
686
|
685
|
```
|
687
|
686
|
|
688
|
|
-#### Self-Signed SSL Server
|
|
687
|
+### Self-Signed SSL Server
|
689
|
688
|
|
690
|
689
|
By default, react-native-fetch-blob does NOT allow connection to unknown certification provider since it's dangerous. If you're going to connect a server with self-signed certification, add `trusty` to `config`. This function is available for version >= `0.5.3`
|
691
|
690
|
|
|
@@ -699,7 +698,7 @@ RNFetchBlob.config({
|
699
|
698
|
})
|
700
|
699
|
```
|
701
|
700
|
|
702
|
|
-### Web API Polyfills
|
|
701
|
+## Web API Polyfills
|
703
|
702
|
|
704
|
703
|
After `0.8.0` we've made some [Web API polyfills](https://github.com/wkh237/react-native-fetch-blob/wiki/Web-API-Polyfills-(experimental)) that makes some browser-based library available in RN.
|
705
|
704
|
|
|
@@ -708,9 +707,7 @@ After `0.8.0` we've made some [Web API polyfills](https://github.com/wkh237/reac
|
708
|
707
|
|
709
|
708
|
Here's a [sample app](https://github.com/wkh237/rn-firebase-storage-upload-sample) that uses polyfills to upload files to FireBase.
|
710
|
709
|
|
711
|
|
-### Performance Tips
|
712
|
|
-
|
713
|
|
----
|
|
710
|
+## Performance Tips
|
714
|
711
|
|
715
|
712
|
**Reduce RCT Bridge and BASE64 Overheard**
|
716
|
713
|
|