A React Native wrapper for AWS iOS/Android S3 SDK.
We currently implements TransferUtility, see iOS/Android docs for more information.
$ npm install react-native-s3 --saveIn XCode, in the project navigator:
- Right click
Libraries➜Add Files to [your project's name], Addnode_modules/react-native-s3/ios/RNS3.xcodeproj. - Add
libRNS3.ato your project'sBuild Phases➜Link Binary With Libraries - Add
$(SRCROOT)/../node_modules/react-native-s3/ios/Frameworksto your project'sBuild Settings➜Framework Search Paths - Add
node_modules/react-native-s3/ios/Frameworks/*.framework,libsqlite3.tbd,libz.tbdto your project'sBuild Phases➜Link Binary With Libraries - Edit
AppDelegate.mof your project
#import "RNS3TransferUtility.h"
......
- (void)application:(UIApplication *)application handleEventsForBackgroundURLSession:(NSString *)identifier completionHandler:(void (^)())completionHandler {
[RNS3TransferUtility interceptApplication:application
handleEventsForBackgroundURLSession:identifier
completionHandler:completionHandler]
}- [Optional] you can set the credentials in
AppDelegate.m
#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"];
......
}- Edit
android/settings.gradleof your project:
...
include ':react-native-s3'
project(':react-native-s3').projectDir = new File(settingsDir, '../node_modules/react-native-s3/android')- Edit
android/app/build.gradleof your project:
...
dependencies {
...
compile project(':react-native-s3')
}- Add package to
MainActivity
......
import com.mybigday.rn.*; // import
public class MainActivity extends ReactActivity {
......
@Override
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new MainReactPackage(),
new RNS3Package() // add package
);
}
}You can use rnpm instead of above steps.
- Edit
android/app/src/main/AndroidManifest.xmlof your project:
<service
android:name="com.amazonaws.mobileconnectors.s3.transferutility.TransferService"
android:enabled="true" />- [Optional] you can set the credentials in
MainActivity:
@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");
}import { transferUtility } from 'react-native-s3';Return: Promise - will resolve arguments:
- Boolean -
trueorfalsedepending on the setup successful.
optionsObjectregionString - a S3 Region (default: eu-west-1)access_keyString - the AWS access key IDsecret_keyString - the AWS secret access keysession_tokenString - (optional) (Android)
Return: Promise - will resolve arguments:
- Boolean -
trueorfalsedepending on the setup successful.
optionsObjectregionString - a S3 Region (default: eu-west-1)identity_pool_idString - the Amazon Cogntio identity poolcachingBoolean - useCognitoCachingCredentialsProviderinstead ofCognitoCredentialsProvider(Android)
See AWS CognitoCredentialsProvider (iOS/Android) for more information.
Return: Promise - will resolve arguments:
- Boolean -
trueorfalsedepending on the setup successful.
New a upload task.
optionsObjectbucketString - a S3 bucket namekeyString - the object key in the bucketfileString - the file path to uploadmetaObjectcontentTypeString - the file content-typecontentMD5String - the file md5 hash
Return: Promise - will resolve, see following arguments:
- Object - a Task object
or reject.
New a download task.
optionsObjectbucketString - a S3 bucket namekeyString - the object key in the bucketfileString - donwload save file path
Return: Promise - will resolve, see following arguments:
- Object - a Task object
or reject.
idNumber - a Task id
idNumber - a Task id
idNumber - a Task id
idNumber - a Task id
Return: Promise - will resolve, see following arguments:
- Boolean -
trueorfalsedepending on the delete task record successful.
Gets a Task object with the given id.
idNumber - a Task id
Return: Promise - will resolve, see following arguments:
- Object - a Task object
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
Subscribe the task changes with the given id.
idNumber - a Task ideventHandlerFunction - arguments:taskObject - a Task object
Unsubscribe the task changes with the given id.
idNumber - a Task id
{
id: Number,
state: String, // task state
// progress of task: bytes / totalBytes
bytes: Number,
totalBytes: Number,
// iOS only part, waiting https://github.com/aws/aws-sdk-android/pull/105
bucket: String,
key: String,
}It will not be immediately refresh, you must subscribe or call getTask(id) to replace it.
waitingin_progresspausecanceledcompletedfailed
BASICCOGNITO
- TransferUtility
- TransferManager
- Bucket Control
- CredentialsProvider
- STS
- TransferUtility
- TransferManager (Deprecated)
- Bucket Control
- CredentialsProvider
- STS