|
@@ -148,30 +148,10 @@ var RNFetchBlob = require('react-native-fetch-blob').default
|
148
|
148
|
|
149
|
149
|
After `0.8.0` react-native-fetch-blob automatically decide how to send the body by checking `Content-Type` in header.
|
150
|
150
|
|
151
|
|
-The rules are shown in the following sample
|
|
151
|
+The rules are shown in the following diagram
|
152
|
152
|
|
153
|
|
-```js
|
154
|
|
-import RNFetchblob from 'react-native-fetch-blob'
|
155
|
|
-
|
156
|
|
-// If body is an Array send as multipart form data
|
157
|
|
-RNFetchBlob.fetch('POST'),'http://upload.server.my' { /* whatever it is */ }, [{ name : 'field1', data : 'test' }])
|
158
|
|
-
|
159
|
|
-// If body is a string starts with prefix 'RNFetchBlob-file://' send request with input stream from the patg
|
160
|
|
-RNFetchBlob.fetch('POST'),'http://upload.server.my' { /* whatever it is */ }, 'RNFetchBlob-file://' + path)
|
161
|
|
-RNFetchBlob.fetch('POST'),'http://upload.server.my' { /* whatever it is */ }, RNFetchBlob.wrap(path))
|
162
|
|
-
|
163
|
|
-// If content-type contains `base64;` or `application/octet` the body will be decoded using BASE64 decoder
|
164
|
|
-RNFetchBlob.fetch('POST','http://upload.server.my', { 'Content-Type' : 'anything;base64' }, BASE64_BODY)
|
165
|
|
-RNFetchBlob.fetch('POST','http://upload.server.my', { 'Content-Type' : 'application/octet-binary' }, BASE64_BODY)
|
166
|
|
-
|
167
|
|
-// Send the data as the string you given
|
168
|
|
-RNFetchBlob.fetch('POST', 'http://upload.server.my', { /*any content-type not matching above rules*/ 'Content-Type' : 'text/foo' }, data)
|
169
|
|
-RNFetchBlob.fetch('POST', 'http://upload.server.my', { 'text/plain' }, 'text in the body')
|
170
|
|
-RNFetchBlob.fetch('POST', 'http://upload.server.my', { 'application/json' }, JSON.stringify(some_data))
|
171
|
|
-
|
172
|
|
-```
|
|
153
|
+<img src="img/RNFB-flow.png" style="width : 90% />
|
173
|
154
|
|
174
|
|
-If no 'Content-Type' field in headers, it will use default content type `application/octet-stream` and convert given `body` to binary data using BASE64 decoder.
|
175
|
155
|
|
176
|
156
|
#### Download example : Fetch files that needs authorization token
|
177
|
157
|
|