Skip to content

Commit

Permalink
adding bucket name to the config file
Browse files Browse the repository at this point in the history
as an optional value
  • Loading branch information
Ondrej Rafaj authored and Ondrej Rafaj committed Dec 17, 2016
1 parent 02c9e94 commit 9732d11
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
20 changes: 14 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Basic S3 access library for Vapor written in Swift

1) Add following package to your ```Package.swift```:
``` Swift
.Package(url: "https://github.com/manGoweb/S3.git", majorVersion: 1, minor: 0)
.Package(url: "https://github.com/manGoweb/S3.git", majorVersion: 1)
```

2) Run ```vapor clean```
Expand All @@ -21,31 +21,39 @@ Import the module ```import S3```

``` Swift
let s3: S3 = try S3(droplet: drop)
let fileData: Data = try s3.get(fileAtPath: "images/image.png", bucketName: "booststore")
let fileData: Data = try s3.get(fileAtPath: "images/image.png")
```

#### Upload data to S3

``` Swift
let s3: S3 = try S3(droplet: drop)
let url = URL.init(fileURLWithPath: "/Users/pro/Dropbox/books/agile-android-software-development.pdf")
try s3.put(fileAtUrl: url, filePath: "books/agile-android-software-development.pdf", bucketName: "booststore", accessControl: .publicRead)
try s3.put(fileAtUrl: url, filePath: "books/agile-android-software-development.pdf", accessControl: .publicRead)
```

#### Delete data from S3

``` Swift
let s3: S3 = try S3(droplet: drop)
try s3.delete(fileAtPath: "images/image.png", bucketName: "booststore")
try s3.delete(fileAtPath: "images/image.png")
```

### Config

Looks like this ```Config/s3.json```:
```
{
"accessKey": "{your-AWS-accees-key}",
"secretKey": "{your-AWS-secret-key}"
"accessKey": "{your-AWS-accees-key}",
"secretKey": "{your-AWS-secret-key}",
"bucket": "{bucket-name}"
}
```
The bucket name is an optional value so you can skip it if you want:
```
{
"accessKey": "{your-AWS-accees-key}",
"secretKey": "{your-AWS-secret-key}"
}
```

Expand Down
7 changes: 6 additions & 1 deletion Sources/S3.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,12 @@ public class S3 {

self.init(accessKey: accessKey, secretKey: secretKey)

self.bucketName = bucketName
if let bucket: String = drop.config["s3", "bucket"]?.string {
self.bucketName = bucket
}
else {
self.bucketName = bucketName
}
}

/**
Expand Down

0 comments on commit 9732d11

Please sign in to comment.