This repository was archived by the owner on Mar 16, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Session API
wkh237 edited this page Jul 4, 2016
·
6 revisions
0.5.0
A session is an object that helps you manage files. It simply maintains a list of file path and let you use dispose()to delete files in this session once and for all.
Add a file path to this session.
Remove a file path from this session (not delete the file).
Returns an array contains file paths in this session.
Delete all files according to paths in the session.
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 ways to remove the files
// remove file using RNFetchblobResponse.flush() object method
RNFetchblob.config({
fileCache : true
})
.fetch('GET', 'http://example.com/download/file')
.then((res) => {
// remove cached file from storage
res.flush()
})
// remove file by specifying a path
RNFetchBlob.fs.unlink('some-file-path').then(() => {
// ...
})You can also grouping requests by using session API, and use dispose to remove them all when needed.
RNFetchblob.config({
fileCache : true
})
.fetch('GET', 'http://example.com/download/file')
.then((res) => {
// set session of a response
res.session('foo')
})
RNFetchblob.config({
// you can also set session beforehand
session : 'foo'
fileCache : true
})
.fetch('GET', 'http://example.com/download/file')
.then((res) => {
// ...
})
// or put an existing file path to the session
RNFetchBlob.session('foo').add('some-file-path')
// remove a file path from the session
RNFetchBlob.session('foo').remove('some-file-path')
// list paths of a session
RNFetchBlob.session('foo').list()
// remove all files in a session
RNFetchBlob.session('foo').dispose().then(() => { ... })