Skip to content
This repository was archived by the owner on Mar 16, 2019. It is now read-only.

Commit e733312

Browse files
committed
Update README.md
1 parent d600648 commit e733312

File tree

1 file changed

+29
-8
lines changed

1 file changed

+29
-8
lines changed

README.md

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22

33
## v0.5.0 Work In Progress README.md
44

5-
Module for upload, download, and files access in JS context. Supports file stream read/write for process large files.
5+
A module provides upload, download, and files access API. Supports file stream read/write for process large files.
66

77
**Why do we need this**
88

99
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).
1010

11-
Therefore you may getting into trouble sometime. For example, you're going to display an image but the file server requires a specific field(for example, "Authorization") in headers or body, 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 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.
11+
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.
1212

13-
This module is designed for these kind of purpose, and also be a substitution of `blob`, so there's a set of file access API added after `v0.5.0`, including basic CRUD method, and file stream reader and writer.
13+
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.
1414

1515
**Pre v0.5.0 Users**
1616

@@ -19,12 +19,12 @@ This update is `backward-compatible` generally you don't have to change existing
1919
## TOC
2020

2121
* [Installation](#user-content-installation)
22-
* [Usages](#user-content-usage)
22+
* [Guide](#user-content-guide)
2323
* [Download file](#user-content-download-example--fetch-files-that-needs-authorization-token)
2424
* [Upload file](#user-content-upload-example--dropbox-files-upload-api)
2525
* [Multipart/form upload](#user-content-multipartform-data-example--post-form-data-with-file-and-data)
2626
* [Upload/Download progress](#user-content-uploaaddownload-progress)
27-
* [Show Downloaded File and Notification in Android Downloads App](#user-content-show-downloaded-file-in-android-downloads-app)
27+
* [Android Media Scanner, and Downloads App Support](#user-content-android-media-scanner-and-downloads-app-support)
2828
* [File access](#user-content-file-access)
2929
* [File stream](#user-content-file-stream)
3030
* [Manage cached files](#user-content-manage-cached-files)
@@ -69,7 +69,7 @@ If you're going to access external storage (say, SD card storage), you might hav
6969

7070
```
7171

72-
## Usage
72+
## Guide
7373

7474
```js
7575
import RNFetchBlob from 'react-native-fetch-blob'
@@ -296,9 +296,29 @@ In `version >= 0.4.2` it is possible to know the upload/download progress.
296296
})
297297
```
298298

299-
#### Show Downloaded File and Notifiction in Android Downloads App
299+
#### Android Media Scanner, and Downloads App Support
300300

301-
When you use `config` API to store response data to file, the file won't be visible in Andoird's "Download" app, if you want to do this, some extra options in `config` is required.
301+
If you want to make a file in `External Storage` becomes visible in Picture, Misuc, or other built-in apps, you will have to use `Media Scanner`. To make this happend, use `scanFile` method in `fs`.
302+
303+
304+
```js
305+
306+
RNFetchBlog
307+
.fetch('GET', 'http://example.com/music.mp3')
308+
.then((res) => RNFetchBlob.fs.scanFile([ { path : res.path(), mime : 'audio/mpeg' } ]))
309+
.then(() => {
310+
// scan file success
311+
})
312+
.catch((err) => {
313+
// scan file error
314+
})
315+
```
316+
317+
If mime is null or undefined, then the mime type will be inferred from the file extension.
318+
319+
**Download Notification and Visibiliy in Download App**
320+
321+
Generally, when you store a file into
302322

303323
```js
304324
RNFetchBlob.config({
@@ -320,6 +340,7 @@ RNFetchBlob.config({
320340
.then(...)
321341
```
322342

343+
323344
#### File Access
324345

325346
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 I realized that, it's hard to find a great solution to manage cached files, every one who use this moudle may need those APIs for there cases.

0 commit comments

Comments
 (0)