From 8ca5c037e16b0712ca628b84bd31800be97bf337 Mon Sep 17 00:00:00 2001 From: Petr Pavlik Date: Fri, 23 Dec 2016 23:56:14 +0100 Subject: [PATCH] Fix destination URL & add support for custom region in config --- Sources/S3.swift | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/Sources/S3.swift b/Sources/S3.swift index 0e30800..9948a41 100644 --- a/Sources/S3.swift +++ b/Sources/S3.swift @@ -77,7 +77,14 @@ public class S3 { throw Error.missingCredentials("secretKey") } - self.init(accessKey: accessKey, secretKey: secretKey) + if let regionString: String = drop.config["s3", "region"]?.string { + guard let region = Region(rawValue: regionString) else { + throw Error.missingCredentials("region") + } + self.init(accessKey: accessKey, secretKey: secretKey, region: region) + } else { + self.init(accessKey: accessKey, secretKey: secretKey) + } if let bucket: String = drop.config["s3", "bucket"]?.string { self.bucketName = bucket @@ -273,8 +280,7 @@ internal extension S3 { throw Error.missingBucketName } - var url: URL = URL(string: "https://s3.amazonaws.com")! - url.appendPathComponent(bucket!) + var url: URL = URL(string: "https://\(bucket!).s3.amazonaws.com")! url.appendPathComponent(fileName) return url }