-
Notifications
You must be signed in to change notification settings - Fork 787
Classes
- RNFetchBlobAndroidDownloadOption
- RNFetchBlobConfig
- RNFetchBlobResponse
- RNFetchBlobResponseInfo
- RNFetchBlobStat
- StatefulPromise
- RNFetchBlobReadStream
- RNFetchBlobWriteStream
0.10.6
Option object for Android Download manager API like android.addCompleteDownload
Title string to be displayed when the file added to Downloads
app.
File description to be displayed when the file added to Downloads
app.
MIME string of the file.
URI string of the file.
Boolean value that determines if notification will be displayed.
A set of configurations that will be injected into a fetch
method, with the following properties.
0.10.6
Set this flag to true
if you wish the request can last as long as possible even the app entering background. Notice that when enable background task, the timeout
does not take effect, also the redirect record will be empty. See #368
0.10.0
When this property is true
, the downloaded data will overwrite the existing file. (true
by default)
// overwrite == true
RNFetchBlob.config({
path : PATH_OF_AN_EXISTING_FILE,
overwrite : true
})
.fetch('GET', 'http://www.example.com')
.then((res) => {
// the file at path `PATH_OF_AN_EXISTING_FILE` will be overwrite by
// the response data from `http://www.example.com`
})
// overwrite == false
RNFetchBlob.config({
path : PATH_OF_AN_EXISTING_FILE,
overwrite : false
})
.fetch('GET', 'http://www.example.com')
.then((res) => {
// the response data from `http://www.example.com` will append
// to the file at path PATH_OF_AN_EXISTING_FILE instead of replace it
})
0.8.0
Set timeout of the request (in milliseconds).
0.5.6
Set this property to true
to display a network indicator on status bar, this feature is only supported on IOS.
0.5.3
Set this property to true
will allow the request create connection with server have self-signed SSL certification. This is not recommended to use in production.
Set this property to true
will makes response data of the fetch
stored in a temp file, by default the temp file will stored in App's own root folder with file name template RNFetchBlob_tmp${timestamp}
.
Set this property to change temp file extension that created by fetch
response data.
When this property has value, fetch
API will try to store response data in the path ignoring fileCache
and appendExt
property.
This is an Android only property, it should be an object with the following properties :
- useDownloadManager : download file using Android download manager or not.
- title : title of the file
- description : File description of the file.
- path : The destination which the file will be downloaded, it SHOULD be a location on external storage (DCIMDir).
- mime : MIME type of the file. By default is
text/plain
- mediaScannable : A
boolean
value, see [Officail Document](https://developer.android.com/reference/android/app/DownloadManager.html#addCompletedDownload(java.lang.String, java.lang.String, boolean, java.lang.String, java.lang.String, long, boolean) - notification : A
boolean
value decide whether show a notification when download complete.
Notice : Android Download Manager only supports
GET
requests
0.10.2-beta.6
Property represents if it automatically follow redirects, default value is true
.
When fetch
success, it resolve a FetchBlobResponse
object as first argument. FetchBlobResponse
object has the following methods (these method are synchronous, so you might take quite a performance impact if the file is big)
returns base64 string of response data (done in native context)
returns json parsed object (done in js context)
returns decoded base64 string (done in js context)
returns file path if the response data is cached in file
return a promise that resolves response data when possible.
return a promise that resolves a readStream
object when possible.
when the response data is cached in a file, this method adds the file into the session. The following usages are equivalent.
RNFetchBlob.session('session-name').add(resp.path())
// or
resp.session('session-name')
info(): RNFetchBlobResponseInfo
This method returns an object contains response information like status code, headers.
0.8.0
Response detail information object like status, headers.
0.8.0
An dictionary contains headers.
Status code of the response.
XMLHttpRequest response type.
RNFetchBlob.fetch response type, in RNFetchBlob.fetch response, when the response data is stored to file system, it should be path
otherwise it depends on the response data, if the data can be encoded into UTF8 string it will be utf8
otherwise base64
.
0.5.0
Statistic data of a file, see the following sample object. This object usually comes from stat and lstat API
{
// file name
filename : 'foo.png',
// folder of the file or the folder itself
path : '/path/to/the/file/without/file/name/',
// size, in bytes
size : 4901,
// `file` or `directory`
type : 'file',
// last modified timestamp
lastModified : 141323298
}
A class inherits Promise
, it has extra methods like progress
, uploadProgress
, and cancel
which can help managing an asynchronous task's state.
0.8.0
Cancel the request when invoking this method.
0.9.0
Add an event listener which will be triggered when StatefulPromise's state changing.
0.5.0
Add an event listener which triggers when data receiving from server.
0.9.6
Add an event listener with custom configuration, see usage.
0.8.0
Add an event listener which triggers when data chunks sent to server.
Add an event listener with custom configuration, see usage.
0.10.0
An IOS only API, when IOS app turns into background network tasks will be terminated after ~180 seconds, in order to handle these expired tasks, you can register an event handler, which will be called after the app become active.
RNFetchBlob.fetch('GET', 'http://example.com')
.expire(() => { console.log('task expired !!') })
.then(() => { ... })
0.5.0
A file stream instance created by fs.readStream
A file stream will NOT open automatically, invoke this method to start read chunks from the file.
Register an event handler handles the chunks read from the stream, when using ascii
encoding chunk
will be an Array contains number 0-255, otherwise it's a string.
Register an event handler handles the chunks read from the stream, when using ascii
encoding chunk
will be an Array contains number 0-255, otherwise it's a string.
Register an event handler which invoked when stream reaches end of file.
0.5.0
A file stream instance created by fs.writeStream
Writes the given data to the stream. If the encoding is "ascii
" the data is expected to be an array of 0..255 numbers, otherwise a string (encoding "utf8
" and "base64
").
Closes the stream.