Skip to content
Merged
38 changes: 38 additions & 0 deletions swift/example_code/s3/presigned-urls/Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// swift-tools-version: 5.9
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
//
// The swift-tools-version declares the minimum version of Swift required to
// build this package.

import PackageDescription

let package = Package(
name: "presigned",
// Let Xcode know the minimum Apple platforms supported.
platforms: [
.macOS(.v13),
.iOS(.v15)
],
dependencies: [
// Dependencies declare other packages that this package depends on.
.package(
url: "https://github.com/awslabs/aws-sdk-swift",
from: "1.0.0"),
.package(
url: "https://github.com/apple/swift-argument-parser.git",
branch: "main"
)
],
targets: [
// Targets are the basic building blocks of a package, defining a module or a test suite.
// Targets can depend on other targets in this package and products from dependencies.
.executableTarget(
name: "presigned",
dependencies: [
.product(name: "AWSS3", package: "aws-sdk-swift"),
.product(name: "ArgumentParser", package: "swift-argument-parser"),
],
path: "Sources")
]
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import Foundation
import ArgumentParser

/// Flags used to identify whether the file is to be uploaded or downloaded.
enum TransferDirection: String, EnumerableFlag {
/// The file transfer is an upload.
case up
/// The file transfer is a download.
case down
}
47 changes: 47 additions & 0 deletions swift/example_code/s3/presigned-urls/Sources/TransferError.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

/// Errors thrown by the example's functions.
enum TransferError: Error {
/// The destination directory for a download is missing or inaccessible.
case directoryError
/// An error occurred while downloading a file from Amazon S3.
case downloadError(_ message: String = "")
/// An error occurred moving the file to its final destination.
case fileMoveError
/// An error occurred when completing a multi-part upload to Amazon S3.
case multipartFinishError
/// An error occurred when starting a multi-part upload to Amazon S3.
case multipartStartError
/// An error occurred while uploading a file to Amazon S3.
case uploadError(_ message: String = "")
/// An error occurred while reading the file's contents.
case readError
/// An error occurred while presigning the URL.
case signingError
/// An error occurred while writing the file's contents.
case writeError

var errorDescription: String? {
switch self {
case .directoryError:
return "The destination directory could not be located or created"
case .downloadError(message: let message):
return "An error occurred attempting to download the file: \(message)"
case .fileMoveError:
return "The file couldn't be moved to the destination directory"
case .multipartFinishError:
return "An error occurred when completing a multi-part upload to Amazon S3."
case .multipartStartError:
return "An error occurred when starting a multi-part upload to Amazon S3."
case .uploadError(message: let message):
return "An error occurred attempting to upload the file: \(message)"
case .readError:
return "An error occurred while reading the file data"
case .signingError:
return "An error occurred while pre-signing the URL"
case .writeError:
return "An error occurred while writing the file data"
}
}
}
Loading
Loading