Skip to content

Commit ee05924

Browse files
authored
Swift: Presigned URLs, downloads, multi-part uploads (#7030)
Swift presigned URLs, downloads, and multi-part uploads
1 parent c0cfd20 commit ee05924

File tree

5 files changed

+607
-0
lines changed

5 files changed

+607
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// swift-tools-version: 5.9
2+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
// SPDX-License-Identifier: Apache-2.0
4+
//
5+
// The swift-tools-version declares the minimum version of Swift required to
6+
// build this package.
7+
8+
import PackageDescription
9+
10+
let package = Package(
11+
name: "presigned",
12+
// Let Xcode know the minimum Apple platforms supported.
13+
platforms: [
14+
.macOS(.v13),
15+
.iOS(.v15)
16+
],
17+
dependencies: [
18+
// Dependencies declare other packages that this package depends on.
19+
.package(
20+
url: "https://github.com/awslabs/aws-sdk-swift",
21+
from: "1.0.0"),
22+
.package(
23+
url: "https://github.com/apple/swift-argument-parser.git",
24+
branch: "main"
25+
)
26+
],
27+
targets: [
28+
// Targets are the basic building blocks of a package, defining a module or a test suite.
29+
// Targets can depend on other targets in this package and products from dependencies.
30+
.executableTarget(
31+
name: "presigned",
32+
dependencies: [
33+
.product(name: "AWSS3", package: "aws-sdk-swift"),
34+
.product(name: "ArgumentParser", package: "swift-argument-parser"),
35+
],
36+
path: "Sources")
37+
]
38+
)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
import Foundation
5+
import ArgumentParser
6+
7+
/// Flags used to identify whether the file is to be uploaded or downloaded.
8+
enum TransferDirection: String, EnumerableFlag {
9+
/// The file transfer is an upload.
10+
case up
11+
/// The file transfer is a download.
12+
case down
13+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
/// Errors thrown by the example's functions.
5+
enum TransferError: Error {
6+
/// The destination directory for a download is missing or inaccessible.
7+
case directoryError
8+
/// An error occurred while downloading a file from Amazon S3.
9+
case downloadError(_ message: String = "")
10+
/// An error occurred moving the file to its final destination.
11+
case fileMoveError
12+
/// An error occurred when completing a multi-part upload to Amazon S3.
13+
case multipartFinishError
14+
/// An error occurred when starting a multi-part upload to Amazon S3.
15+
case multipartStartError
16+
/// An error occurred while uploading a file to Amazon S3.
17+
case uploadError(_ message: String = "")
18+
/// An error occurred while reading the file's contents.
19+
case readError
20+
/// An error occurred while presigning the URL.
21+
case signingError
22+
/// An error occurred while writing the file's contents.
23+
case writeError
24+
25+
var errorDescription: String? {
26+
switch self {
27+
case .directoryError:
28+
return "The destination directory could not be located or created"
29+
case .downloadError(message: let message):
30+
return "An error occurred attempting to download the file: \(message)"
31+
case .fileMoveError:
32+
return "The file couldn't be moved to the destination directory"
33+
case .multipartFinishError:
34+
return "An error occurred when completing a multi-part upload to Amazon S3."
35+
case .multipartStartError:
36+
return "An error occurred when starting a multi-part upload to Amazon S3."
37+
case .uploadError(message: let message):
38+
return "An error occurred attempting to upload the file: \(message)"
39+
case .readError:
40+
return "An error occurred while reading the file data"
41+
case .signingError:
42+
return "An error occurred while pre-signing the URL"
43+
case .writeError:
44+
return "An error occurred while writing the file data"
45+
}
46+
}
47+
}

0 commit comments

Comments
 (0)