From d6dff77425dd76a1dc2d50c0e304703608486c20 Mon Sep 17 00:00:00 2001 From: Ondrej Rafaj Date: Sat, 26 May 2018 23:03:28 +0100 Subject: [PATCH] return file url from a client --- Sources/S3/Extensions/S3+Get.swift | 9 +++++++++ Sources/S3/Protocols/S3Client.swift | 3 +++ Sources/S3/S3.swift | 2 +- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/Sources/S3/Extensions/S3+Get.swift b/Sources/S3/Extensions/S3+Get.swift index eff14fe..913f731 100644 --- a/Sources/S3/Extensions/S3+Get.swift +++ b/Sources/S3/Extensions/S3+Get.swift @@ -12,6 +12,15 @@ import Vapor // Helper S3 extension for loading (getting) files by their URL/path public extension S3 { + // MARK: URL + + /// File URL + public func url(fileInfo file: LocationConvertible, on container: Container) throws -> URL { + let builder = urlBuilder(for: container) + let url = try builder.url(file: file) + return url + } + // MARK: Get /// Retrieve file data from S3 diff --git a/Sources/S3/Protocols/S3Client.swift b/Sources/S3/Protocols/S3Client.swift index 3e577b0..c0981db 100644 --- a/Sources/S3/Protocols/S3Client.swift +++ b/Sources/S3/Protocols/S3Client.swift @@ -66,6 +66,9 @@ public protocol S3Client: Service { /// Upload file to S3 func put(string: String, mime: MediaType, destination: String, bucket: String?, access: AccessControlList, on: Container) throws -> Future + /// File URL + func url(fileInfo file: LocationConvertible, on container: Container) throws -> URL + /// Retrieve file data from S3 func get(fileInfo file: LocationConvertible, on container: Container) throws -> Future diff --git a/Sources/S3/S3.swift b/Sources/S3/S3.swift index 9a27f83..8f66c38 100755 --- a/Sources/S3/S3.swift +++ b/Sources/S3/S3.swift @@ -13,7 +13,7 @@ import HTTP /// Main S3 class -public class S3: S3Client { +public class S3: S3Client { /// Error messages public enum Error: Swift.Error {