API
January 23, 2017 ยท View on GitHub
Usage
import { transferUtility } from 'react-native-s3';
transferUtility.setupWithNative()
Return: Promise - will resolve arguments:
- Boolean -
trueorfalsedepending on the setup successful.
transferUtility.setupWithBasic(options)
optionsObjectregionString - a S3 Region (default: eu-west-1)access_keyString - the AWS access key IDsecret_keyString - the AWS secret access keysession_tokenString - (optional)remember_last_instanceBoolean - keep the last transferUtility instance when JS reload (default: true) (iOS)
Return: Promise - will resolve arguments:
- Boolean -
trueorfalsedepending on the setup successful.
transferUtility.setupWithCognito(options)
optionsObjectregionString - a S3 Region (default: eu-west-1)identity_pool_idString - the Amazon Cogntio identity poolcognito_regionString - a Cognito Region (default: eu-west-1)cachingBoolean - useCognitoCachingCredentialsProviderinstead ofCognitoCredentialsProvider(Android)remember_last_instanceBoolean - keep the last transferUtility instance when JS reload (default: true) (iOS)
See AWS CognitoCredentialsProvider (iOS/Android) for more information.
Return: Promise - will resolve arguments:
- Boolean -
trueorfalsedepending on the setup successful.
transferUtility.enableProgressSent(enabled)
- enabled Boolean - Allow
in_progressevent send to JS runtime. (Default: true)
Return: Promise
transferUtility.upload(options)
New a upload task.
optionsObject
Return: Promise - will resolve, see following arguments:
- Object - a Task object
or reject.
transferUtility.download(options)
New a download task.
optionsObjectbucketString - a S3 bucket namekeyString - the object key/destination in the bucketfileString - donwload save file path
Return: Promise - will resolve, see following arguments:
- Object - a Task object
or reject.
transferUtility.pause(id)
idNumber - a Task id
transferUtility.resume(id)
idNumber - a Task id
transferUtility.cancel(id)
idNumber - a Task id
transferUtility.deleteRecord(id) (Android)
idNumber - a Task id
Return: Promise - will resolve, see following arguments:
- Boolean -
trueorfalsedepending on the delete task record successful.
transferUtility.getTask(id)
Gets a Task object with the given id.
idNumber - a Task id
Return: Promise - will resolve, see following arguments:
- Object - a Task object
transferUtility.getTasks(type, idAsKey)
Gets a Task object list with the type.
typeString - enum:upload,downloadidAsKeyBoolean - true: return Object with id as key, false: return Array
Return: Promise - will resolve, see following arguments:
- Array - a Task object list
transferUtility.subscribe(id, eventHandler)
Subscribe the task changes with the given id.
idNumber - a Task ideventHandlerFunction - arguments:errObject - error information object or null if no errortaskObject - a Task object
transferUtility.unsubscribe(id, eventHandler)
Unsubscribe task change listener eventHandler with the given id.
If eventHandler is not exists, it will unsubscribe all task change listeners with the given id.
idNumber - a Task id
The Task object structure
{
id: Number,
state: String, // task state
// progress of task: bytes / totalBytes
bytes: Number,
totalBytes: Number,
bucket: String,
key: String
}
It will not be immediately refresh, you must subscribe or call getTask(id) to replace it.
The Task states
waitingin_progresspausedcanceledcompletedfailed