Home

Awesome

React Native AWS S3

NPM version Build Status Dependency Status devDependency Status

A React Native wrapper for AWS iOS/Android S3 SDK.

We currently implements TransferUtility, it allow you to upload / download tasks in the background, very suitable for transferring large files, you can freely subscribe / unsubscribe, pause / resume / cancel the task.

See iOS/Android docs for more information.

Known issues

Installation

$ npm install react-native-s3 --save

Setup

iOS

NOTE Only supported iOS ^8.0.

In XCode, in the project navigator:

#import "RNS3TransferUtility.h"

......

- (void)application:(UIApplication *)application handleEventsForBackgroundURLSession:(NSString *)identifier completionHandler:(void (^)())completionHandler {
  [RNS3TransferUtility interceptApplication:application
        handleEventsForBackgroundURLSession:identifier
                          completionHandler:completionHandler];
}
#import "RNS3TransferUtility.h"

......

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
  [[RNS3TransferUtility nativeCredentialsOptions] setObject:@"eu-west-1" forKey:@"region"];
  [[RNS3TransferUtility nativeCredentialsOptions] setObject:[NSNumber numberWithInt:[RNS3TransferUtility credentialType:@"BASIC"]] forKey:@"type"];
  [[RNS3TransferUtility nativeCredentialsOptions] setObject:@"your_access_key_here" forKey:@"access_key"];
  [[RNS3TransferUtility nativeCredentialsOptions] setObject:@"your_secret_key_here" forKey:@"secret_key"];
  ......
}

Android

...
include ':react-native-s3'
project(':react-native-s3').projectDir = new File(settingsDir, '../node_modules/react-native-s3/android')
...
dependencies {
    ...
    compile project(':react-native-s3')
}
......

import com.mybigday.rns3.*;   // import

public class MainApplication extends Application implements ReactApplication {
  private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
    ......

    @Override
    protected List<ReactPackage> getPackages() {
      return Arrays.<ReactPackage>asList(
        new MainReactPackage(),
        new RNS3Package(),  // add package
      );
    }
  };

  ......
}

You can use rnpm instead of above steps.

<service
  android:name="com.amazonaws.mobileconnectors.s3.transferutility.TransferService"
  android:enabled="true" />
import android.os.Bundle;
import com.mybigday.rns3.RNS3TransferUtility;

public class MainActivity extends ReactActivity {
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    RNS3TransferUtility.nativeCredentialsOptions.put("region", "eu-west-1");
    RNS3TransferUtility.nativeCredentialsOptions.put("type", RNS3TransferUtility.CredentialType.BASIC);
    RNS3TransferUtility.nativeCredentialsOptions.put("access_key", "your_access_key_here");
    RNS3TransferUtility.nativeCredentialsOptions.put("secret_key", "your_secret_key_here");
  }

  ......
}

The nativeCredentialsOptions type

Usage

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

See API.md for more information.

Alternatives

License

MIT