|
@@ -2,15 +2,15 @@
|
2
|
2
|
|
3
|
3
|
## v0.5.0 Work In Progress README.md
|
4
|
4
|
|
5
|
|
-A react-native module for upload, and download files with custom headers. Supports blob response data, upload/download progress, and file reader API that enables you process file content in js context (such as display image data, string or image process).
|
|
5
|
+A react-native module for upload, and download files with customizable headers. Supports binary response/request data, upload/download progress. It also has a file stream reader API that enables you to handle files in JS context (such as display image data, and process string or data).
|
6
|
6
|
|
7
|
|
-If you're dealing with image or file server that requires special field in the header, or you're having problem with `fetch` API when receiving blob data, you might try this module.
|
|
7
|
+If you're getting into trouble with image or file server that requires specific fields in the header, or you're having problem with `fetch` API when sending/receiving binary data, you might try this module as well.
|
8
|
8
|
|
9
|
9
|
See [[fetch] Does fetch with blob() marshal data across the bridge?](https://github.com/facebook/react-native/issues/854) for the reason why we made this module.
|
10
|
10
|
|
11
|
|
-In latest version (v0.5.0), you can upload/download files directly with file path. We've also introduced `file stream` API for reading **large files** from storage, see [Examples](#user-content-usage) bellow.
|
|
11
|
+In latest version (v0.5.0), you can either `upload` or `download` files simply using a file path. We've also introduced `file stream` API in this version for reading files (especially for **large ones**) from storage, see [Examples](#user-content-usage) bellow.
|
12
|
12
|
|
13
|
|
-This module implements native HTTP request, supports both Android (uses awesome native library [AsyncHttpClient](https://github.com/AsyncHttpClient/async-http-client])) and IOS.
|
|
13
|
+This module implements native HTTP request methods, supports both Android (uses awesome native library [AsyncHttpClient](https://github.com/AsyncHttpClient/async-http-client])) and IOS.
|
14
|
14
|
|
15
|
15
|
## Usage
|
16
|
16
|
|
|
@@ -23,6 +23,7 @@ This module implements native HTTP request, supports both Android (uses awesome
|
23
|
23
|
* [File stream reader](#user-content-file-stream-reader)
|
24
|
24
|
* [Release cache files](#user-content-release-cache-files)
|
25
|
25
|
* [API](#user-content-api)
|
|
26
|
+* [Development](#user-content-development)
|
26
|
27
|
|
27
|
28
|
## Installation
|
28
|
29
|
|
|
@@ -38,6 +39,25 @@ Link package using [rnpm](https://github.com/rnpm/rnpm)
|
38
|
39
|
rnpm link
|
39
|
40
|
```
|
40
|
41
|
|
|
42
|
+**Android Access Permission to External storage (Optional)**
|
|
43
|
+
|
|
44
|
+If you're going to access external storage (say, SD card storage), you might have to add the following line to `AndroidManifetst.xml`.
|
|
45
|
+
|
|
46
|
+```diff
|
|
47
|
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
|
48
|
+ package="com.rnfetchblobtest"
|
|
49
|
+ android:versionCode="1"
|
|
50
|
+ android:versionName="1.0">
|
|
51
|
+
|
|
52
|
+ <uses-permission android:name="android.permission.INTERNET" />
|
|
53
|
+ <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
|
|
54
|
++ <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
|
|
55
|
++ <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
|
56
|
+
|
|
57
|
+ ...
|
|
58
|
+
|
|
59
|
+```
|
|
60
|
+
|
41
|
61
|
## Usage
|
42
|
62
|
|
43
|
63
|
```js
|
|
@@ -281,7 +301,60 @@ stream.onEnd(() => {
|
281
|
301
|
|
282
|
302
|
#### Release cache files
|
283
|
303
|
|
284
|
|
-TODO
|
|
304
|
+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 way to remove the files
|
|
305
|
+
|
|
306
|
+```js
|
|
307
|
+
|
|
308
|
+ // remove file using RNFetchblobResponse.flush() object method
|
|
309
|
+ RNFetchblob.config({
|
|
310
|
+ fileCache : true
|
|
311
|
+ })
|
|
312
|
+ .fetch('GET', 'http://example.com/download/file')
|
|
313
|
+ .then((res) => {
|
|
314
|
+ // remove cached file from storage
|
|
315
|
+ res.flush()
|
|
316
|
+ })
|
|
317
|
+
|
|
318
|
+ // remove file by specifying a path
|
|
319
|
+ RNFetchBlob.unlink('some-file-path').then(() => {
|
|
320
|
+ // ...
|
|
321
|
+ })
|
|
322
|
+
|
|
323
|
+```
|
|
324
|
+
|
|
325
|
+You can also group the requests by using `session` API, and use `dispose` to remove them all when needed.
|
|
326
|
+
|
|
327
|
+```js
|
|
328
|
+
|
|
329
|
+ RNFetchblob.config({
|
|
330
|
+ fileCache : true
|
|
331
|
+ })
|
|
332
|
+ .fetch('GET', 'http://example.com/download/file')
|
|
333
|
+ .then((res) => {
|
|
334
|
+ // set session of a response
|
|
335
|
+ res.session('foo')
|
|
336
|
+ })
|
|
337
|
+
|
|
338
|
+ RNFetchblob.config({
|
|
339
|
+ // you can also set session before hand
|
|
340
|
+ session : 'foo'
|
|
341
|
+ fileCache : true
|
|
342
|
+ })
|
|
343
|
+ .fetch('GET', 'http://example.com/download/file')
|
|
344
|
+ .then((res) => {
|
|
345
|
+ // ...
|
|
346
|
+ })
|
|
347
|
+
|
|
348
|
+ // or put an existing file path to the session
|
|
349
|
+ RNFetchBlob.session('foo').add('some-file-path')
|
|
350
|
+ // remove a file path from the session
|
|
351
|
+ RNFetchBlob.session('foo').remove('some-file-path')
|
|
352
|
+ // list paths of a session
|
|
353
|
+ RNFetchBlob.session('foo').list()
|
|
354
|
+ // remove all files in a session
|
|
355
|
+ RNFetchBlob.session('foo').dispose().then(() => { ... })
|
|
356
|
+
|
|
357
|
+```
|
285
|
358
|
|
286
|
359
|
## API
|
287
|
360
|
|