You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Mar 16, 2019. It is now read-only.
Copy file name to clipboardExpand all lines: README.md
+9-3Lines changed: 9 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -6,7 +6,7 @@ A module provides upload, download, and files access API. Supports file stream r
6
6
7
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
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.
// 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
210
}, RNFetchBlob.wrap(PATH_TO_THE_FILE))
210
211
.then((res) => {
211
212
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
257
258
{
258
259
name :'avatar',
259
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
263
data:RNFetchBlob.wrap(PATH_TO_THE_FILE)
262
264
},
263
265
// elements without property `filename` will be sent as plain text
@@ -512,6 +514,10 @@ Register on progress event handler for a fetch request.
512
514
513
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.
0 commit comments