Skip to content

Latest commit

 

History

History
154 lines (102 loc) · 4.59 KB

API.md

File metadata and controls

154 lines (102 loc) · 4.59 KB

API

Usage

import { transferUtility } from 'react-native-s3';

transferUtility.setupWithNative()

Return: Promise - will resolve arguments:

  • Boolean - true or false depending on the setup successful.

transferUtility.setupWithBasic(options)

  • options Object
    • region String - a S3 Region (default: eu-west-1)
    • access_key String - the AWS access key ID
    • secret_key String - the AWS secret access key
    • session_token String - (optional)
    • remember_last_instance Boolean - keep the last transferUtility instance when JS reload (default: true) (iOS)

Return: Promise - will resolve arguments:

  • Boolean - true or false depending on the setup successful.

transferUtility.setupWithCognito(options)

  • options Object
    • region String - a S3 Region (default: eu-west-1)
    • identity_pool_id String - the Amazon Cogntio identity pool
    • cognito_region String - a Cognito Region (default: eu-west-1)
    • caching Boolean - use CognitoCachingCredentialsProvider instead of CognitoCredentialsProvider (Android)
    • remember_last_instance Boolean - 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 - true or false depending on the setup successful.

transferUtility.enableProgressSent(enabled)

  • enabled Boolean - Allow in_progress event send to JS runtime. (Default: true)

Return: Promise

transferUtility.upload(options)

New a upload task.

  • options Object
    • bucket String - a S3 bucket name
    • key String - the object key/destination in the bucket
    • file String - the file path to upload
    • meta Object
      • Content-Type String - the file content-type
      • See: iOS/Android

Return: Promise - will resolve, see following arguments:

  • Object - a Task object

or reject.

transferUtility.download(options)

New a download task.

  • options Object
    • bucket String - a S3 bucket name
    • key String - the object key/destination in the bucket
    • file String - donwload save file path

Return: Promise - will resolve, see following arguments:

  • Object - a Task object

or reject.

transferUtility.pause(id)

  • id Number - a Task id

transferUtility.resume(id)

  • id Number - a Task id

transferUtility.cancel(id)

  • id Number - a Task id

transferUtility.deleteRecord(id) (Android)

  • id Number - a Task id

Return: Promise - will resolve, see following arguments:

  • Boolean - true or false depending on the delete task record successful.

transferUtility.getTask(id)

Gets a Task object with the given id.

  • id Number - 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.

  • type String - enum: upload, download
  • idAsKey Boolean - 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.

  • id Number - a Task id
  • eventHandler Function - arguments:
    • err Object - error information object or null if no error
    • task Object - 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.

  • id Number - 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

  • waiting
  • in_progress
  • paused
  • canceled
  • completed
  • failed