Skip to content

Commit f8a4657

Browse files
committed
Initial commit
0 parents  commit f8a4657

52 files changed

Lines changed: 4101 additions & 0 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# OSX
2+
#
3+
.DS_Store
4+
5+
# Xcode
6+
#
7+
build/
8+
*.pbxuser
9+
!default.pbxuser
10+
*.mode1v3
11+
!default.mode1v3
12+
*.mode2v3
13+
!default.mode2v3
14+
*.perspectivev3
15+
!default.perspectivev3
16+
xcuserdata
17+
*.xccheckout
18+
*.moved-aside
19+
DerivedData
20+
*.hmap
21+
*.ipa
22+
*.xcuserstate
23+
project.xcworkspace
24+
25+
## iOS framework
26+
#
27+
*.framework
28+
29+
# Android/IJ
30+
#
31+
.idea
32+
.gradle
33+
local.properties
34+
*.iml
35+
36+
# node.js
37+
#
38+
node_modules/
39+
npm-debug.log

.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
example

LICENSE.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
The MIT License (MIT)
3+
4+
Copyright (c) 2016 Jhen-Jie Hong
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in all
14+
copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
SOFTWARE.

README.md

Lines changed: 289 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,289 @@
1+
# React Native AWS S3
2+
3+
A React Native wrapper for AWS [iOS](https://github.com/aws/aws-sdk-ios)/[Android](https://github.com/aws/aws-sdk-android) S3 SDK.
4+
5+
We currently implements `TransferUtility`, see [iOS](http://docs.aws.amazon.com/mobile/sdkforios/developerguide/s3transferutility.html)/[Android](http://docs.aws.amazon.com/mobile/sdkforandroid/developerguide/getting-started-store-retrieve-s3-transferutility.html) docs for more information.
6+
7+
## Installation
8+
9+
```bash
10+
$ npm install react-native-s3 --save
11+
```
12+
13+
## Setup
14+
15+
#### iOS
16+
17+
In XCode, in the project navigator:
18+
19+
* Right click `Libraries``Add Files to [your project's name]`, Add `node_modules/react-native-s3/ios/RNS3.xcodeproj`.
20+
* Add `libRNS3.a` to your project's `Build Phases``Link Binary With Libraries`
21+
* Add `$(SRCROOT)/../node_modules/react-native-s3/ios/Frameworks` to your project's `Build Settings``Framework Search Paths`
22+
* Add `node_modules/react-native-s3/ios/Frameworks/*.framework`, `libsqlite3.tbd`, `libz.tbd` to your project's `Build Phases``Link Binary With Libraries`
23+
* Edit `AppDelegate.m` of your project
24+
25+
```objective-c
26+
#import "RNS3TransferUtility.h"
27+
28+
......
29+
30+
- (void)application:(UIApplication *)application handleEventsForBackgroundURLSession:(NSString *)identifier completionHandler:(void (^)())completionHandler {
31+
[RNS3TransferUtility interceptApplication:application
32+
handleEventsForBackgroundURLSession:identifier
33+
completionHandler:completionHandler]
34+
}
35+
```
36+
37+
* __*[Optional]*__ you can set the credentials in `AppDelegate.m`
38+
39+
```objective-c
40+
#import "RNS3TransferUtility.h"
41+
42+
......
43+
44+
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
45+
{
46+
[[RNS3TransferUtility nativeCredentialsOptions] setObject:@"eu-west-1" forKey:@"region"];
47+
[[RNS3TransferUtility nativeCredentialsOptions] setObject:[NSNumber numberWithInt:[RNS3TransferUtility credentialType:@"BASIC"]] forKey:@"type"];
48+
[[RNS3TransferUtility nativeCredentialsOptions] setObject:@"your_access_key_here" forKey:@"access_key"];
49+
[[RNS3TransferUtility nativeCredentialsOptions] setObject:@"your_secret_key_here" forKey:@"secret_key"];
50+
......
51+
}
52+
```
53+
54+
#### Android
55+
56+
* Edit `android/settings.gradle` of your project:
57+
58+
```gradle
59+
...
60+
include ':react-native-s3'
61+
project(':react-native-s3').projectDir = new File(settingsDir, '../node_modules/react-native-s3/android')
62+
```
63+
64+
* Edit `android/app/build.gradle` of your project:
65+
66+
```gradle
67+
...
68+
dependencies {
69+
...
70+
compile project(':react-native-s3')
71+
}
72+
```
73+
74+
* Add package to `MainActivity`
75+
76+
```java
77+
......
78+
79+
import com.mybigday.rn.*; // import
80+
81+
public class MainActivity extends ReactActivity {
82+
83+
......
84+
85+
@Override
86+
protected List<ReactPackage> getPackages() {
87+
return Arrays.<ReactPackage>asList(
88+
new MainReactPackage(),
89+
new RNS3Package() // add package
90+
);
91+
}
92+
}
93+
```
94+
95+
You can use [rnpm](https://github.com/rnpm/rnpm) instead of above steps.
96+
97+
* Edit `android/app/src/main/AndroidManifest.xml` of your project:
98+
99+
```xml
100+
<service
101+
android:name="com.amazonaws.mobileconnectors.s3.transferutility.TransferService"
102+
android:enabled="true" />
103+
```
104+
105+
* __*[Optional]*__ you can set the credentials in `MainActivity`:
106+
107+
```java
108+
@Override
109+
public void onCreate(Bundle savedInstanceState) {
110+
super.onCreate(savedInstanceState);
111+
112+
RNS3TransferUtility.nativeCredentialsOptions.put("region", "eu-west-1");
113+
RNS3TransferUtility.nativeCredentialsOptions.put("type", RNS3TransferUtility.CredentialType.BASIC);
114+
RNS3TransferUtility.nativeCredentialsOptions.put("access_key", "your_access_key_here");
115+
RNS3TransferUtility.nativeCredentialsOptions.put("secret_key", "your_secret_key_here");
116+
}
117+
118+
```
119+
120+
## Usage
121+
122+
```js
123+
import { transferUtility } from 'react-native-s3';
124+
```
125+
126+
## API
127+
128+
#### `transferUtility.setupWithNative()`
129+
130+
Return: Boolean - `true` or `false` depending on the setup successful.
131+
132+
#### `transferUtility.setupWithBasic(options)`
133+
134+
* `options` Object
135+
* `region` String - a S3 Region (default: eu-west-1)
136+
* `access_key` String - the AWS access key ID
137+
* `secret_key` String - the AWS secret access key
138+
* `session_token` String - (optional) __(Android)__
139+
140+
Return: Promise - will resolve arguments:
141+
* Boolean - `true` or `false` depending on the setup successful.
142+
143+
#### `transferUtility.setupWithCognito(options)`
144+
145+
* `options` Object
146+
* `region` String - a S3 Region (default: eu-west-1)
147+
* `identity_pool_id` String - the Amazon Cogntio identity pool
148+
* `caching` Boolean - use `CognitoCachingCredentialsProvider` instead of `CognitoCredentialsProvider` __(Android)__
149+
150+
See AWS CognitoCredentialsProvider ([iOS](http://docs.aws.amazon.com/AWSiOSSDK/latest/Classes/AWSCognitoCredentialsProvider.html)/[Android](http://docs.aws.amazon.com/AWSAndroidSDK/latest/javadoc/com/amazonaws/auth/CognitoCredentialsProvider.html)) for more information.
151+
152+
Return: Promise - will resolve arguments:
153+
* Boolean - `true` or `false` depending on the setup successful.
154+
155+
#### `transferUtility.upload(options)`
156+
157+
New a upload task.
158+
159+
* `options` Object
160+
* `bucket` String - a S3 bucket name
161+
* `key` String - the object key in the bucket
162+
* `file` String - the file path to upload
163+
* `meta` Object
164+
* `contentType` String - the file content-type
165+
* `contentMD5` String - the file md5 hash
166+
167+
Return: Promise - will resolve, see following arguments:
168+
* Object - a [Task](#the-task-object-structure) object
169+
170+
or reject.
171+
172+
#### `transferUtility.download(options)`
173+
174+
New a download task.
175+
176+
* `options` Object
177+
* `bucket` String - a S3 bucket name
178+
* `key` String - the object key in the bucket
179+
* `file` String - donwload save file path
180+
181+
Return: Promise - will resolve, see following arguments:
182+
* Object - a [Task](#the-task-object-structure) object
183+
184+
or reject.
185+
186+
#### `transferUtility.pause(id)`
187+
188+
* `id` Number - a Task id
189+
190+
#### `transferUtility.resume(id)`
191+
192+
* `id` Number - a Task id
193+
194+
#### `transferUtility.cancel(id)`
195+
196+
* `id` Number - a Task id
197+
198+
#### `transferUtility.deleteRecord(id)` __(Android)__
199+
200+
* `id` Number - a Task id
201+
202+
Return: Promise - will resolve, see following arguments:
203+
* Boolean - `true` or `false` depending on the delete task record successful.
204+
205+
#### `transferUtility.getTask(id)`
206+
207+
Gets a Task object with the given id.
208+
209+
* `id` Number - a Task id
210+
211+
Return: Promise - will resolve, see following arguments:
212+
* Object - a [Task](#the-task-object-structure) object
213+
214+
#### `transferUtility.getTasks(type, idAsKey)`
215+
216+
Gets a Task object list with the type.
217+
218+
* `type` String - enum: `upload`, `download`
219+
* `idAsKey` Boolean - true: return Object with id as key, false: return Array
220+
221+
Return: Promise - will resolve, see following arguments:
222+
* Array - a [Task](#the-task-object-structure) object list
223+
224+
#### `transferUtility.subscribe(id, eventHandler)`
225+
226+
Subscribe the task changes with the given id.
227+
228+
* `id` Number - a Task id
229+
* `eventHandler` Function - arguments:
230+
* `task` Object - a [Task](#the-task-object-structure) object
231+
232+
#### `transferUtility.unsubscribe(id)`
233+
234+
Unsubscribe the task changes with the given id.
235+
236+
* `id` Number - a Task id
237+
238+
## The `Task` object structure
239+
240+
```js
241+
{
242+
id: Number,
243+
state: String, // task state
244+
// progress of task: bytes / totalBytes
245+
bytes: Number,
246+
totalBytes: Number,
247+
// iOS only part, waiting https://github.com/aws/aws-sdk-android/pull/105
248+
bucket: String,
249+
key: String,
250+
}
251+
```
252+
253+
It will not be immediately refresh, you must `subscribe` or call `getTask(id)` to replace it.
254+
255+
## The `Task` states
256+
257+
* `waiting`
258+
* `in_progress`
259+
* `pause`
260+
* `canceled`
261+
* `completed`
262+
* `failed`
263+
264+
## The `nativeCredentialsOptions` type
265+
266+
* `BASIC`
267+
* `COGNITO`
268+
269+
## Roadmap
270+
271+
#### iOS
272+
273+
- [x] TransferUtility
274+
- [ ] TransferManager
275+
- [ ] Bucket Control
276+
- CredentialsProvider
277+
- [ ] STS
278+
279+
#### Android
280+
281+
- [x] TransferUtility
282+
- [ ] TransferManager (Deprecated)
283+
- [ ] Bucket Control
284+
- CredentialsProvider
285+
- [ ] STS
286+
287+
## License
288+
289+
[MIT](LICENSE.md)

android/build.gradle

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
buildscript {
2+
repositories {
3+
jcenter()
4+
}
5+
6+
dependencies {
7+
classpath 'com.android.tools.build:gradle:1.3.1'
8+
}
9+
}
10+
11+
apply plugin: 'com.android.library'
12+
13+
android {
14+
compileSdkVersion 23
15+
buildToolsVersion "23.0.1"
16+
17+
defaultConfig {
18+
minSdkVersion 16
19+
targetSdkVersion 22
20+
versionCode 1
21+
versionName "1.0"
22+
}
23+
lintOptions {
24+
abortOnError false
25+
}
26+
}
27+
28+
repositories {
29+
mavenCentral()
30+
maven {
31+
url "$projectDir/../../react-native/android"
32+
}
33+
}
34+
35+
dependencies {
36+
compile 'com.facebook.react:react-native:+'
37+
compile 'com.amazonaws:aws-android-sdk-core:2.2.+'
38+
compile 'com.amazonaws:aws-android-sdk-cognito:2.2.+'
39+
compile 'com.amazonaws:aws-android-sdk-s3:2.2.+'
40+
}

0 commit comments

Comments
 (0)