Skip to content

Commit 9732d11

Browse files
Ondrej RafajOndrej Rafaj
authored andcommitted
adding bucket name to the config file
as an optional value
1 parent 02c9e94 commit 9732d11

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

README.md

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Basic S3 access library for Vapor written in Swift
66

77
1) Add following package to your ```Package.swift```:
88
``` Swift
9-
.Package(url: "https://github.com/manGoweb/S3.git", majorVersion: 1, minor: 0)
9+
.Package(url: "https://github.com/manGoweb/S3.git", majorVersion: 1)
1010
```
1111

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

2222
``` Swift
2323
let s3: S3 = try S3(droplet: drop)
24-
let fileData: Data = try s3.get(fileAtPath: "images/image.png", bucketName: "booststore")
24+
let fileData: Data = try s3.get(fileAtPath: "images/image.png")
2525
```
2626

2727
#### Upload data to S3
2828

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

3535
#### Delete data from S3
3636

3737
``` Swift
3838
let s3: S3 = try S3(droplet: drop)
39-
try s3.delete(fileAtPath: "images/image.png", bucketName: "booststore")
39+
try s3.delete(fileAtPath: "images/image.png")
4040
```
4141

4242
### Config
4343

4444
Looks like this ```Config/s3.json```:
4545
```
4646
{
47-
"accessKey": "{your-AWS-accees-key}",
48-
"secretKey": "{your-AWS-secret-key}"
47+
"accessKey": "{your-AWS-accees-key}",
48+
"secretKey": "{your-AWS-secret-key}",
49+
"bucket": "{bucket-name}"
50+
}
51+
```
52+
The bucket name is an optional value so you can skip it if you want:
53+
```
54+
{
55+
"accessKey": "{your-AWS-accees-key}",
56+
"secretKey": "{your-AWS-secret-key}"
4957
}
5058
```
5159

Sources/S3.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,12 @@ public class S3 {
7878

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

81-
self.bucketName = bucketName
81+
if let bucket: String = drop.config["s3", "bucket"]?.string {
82+
self.bucketName = bucket
83+
}
84+
else {
85+
self.bucketName = bucketName
86+
}
8287
}
8388

8489
/**

0 commit comments

Comments
 (0)