fix: Fix number of parts calculation for MPU (#21)
Fix number of parts calculation for mpu
Fix gap in logic where targetPartSizeBytes gets used becaues it’s bigger than ceiling division of payloadSize / 10000.
Fix compiler error
Co-authored-by: Sichan Yoo chanyoo@amazon.com
Amazon S3 Transfer Manager for Swift
⚠️ Developer Preview
This library is currently in developer preview and is NOT recommended for production environments.
It is meant for early access and feedback gathering at this time. We’d love to hear from you on use cases, feature prioritization, and API feedback.
See the AWS SDK and Tools maintenance policy descriptions for more information.
Overview
The Amazon S3 Transfer Manager for Swift (S3TM for short) is a high-level library built on top of the AWS Swift SDK S3 client. It provides an intuitive transfer API for reliable and performant data transfer between your Swift application and Amazon S3, as well as the ability to monitor the progress of the transfers in real-time.
There are 4 transfer operations supported by S3TM:
The S3TM allows monitoring the progress of all 4 operations listed above.
Getting Started
Add the dependency to your Xcode project
.xcodeprojfile, located at the top of the file navigator on the left pane..xcodeprojfile window.Package Dependenciestab, and click+button.Search or Enter Package URLsearch bar, entergit@github.com:aws/aws-sdk-swift-s3-transfer-manager.git.S3TransferManagermodule to.Add the dependency to your Swift package
S3TransferManagermodule dependency to the target that needs it. For example:Initialize the S3 Transfer Manager
You can initialize a S3TM instance with all-default settings by simply doing this:
Or you could pass the config object to the initializer to customize S3TM by doing this:
For more information on what each configuration does, please refer to the documentation comments on S3TransferManagerConfig.
Amazon S3 Transfer Manager for Swift usage examples
Upload an object
To upload a file to Amazon S3, you need to provide the input struct
UploadObjectInput, which contains a subset ofPutObjectInputstruct properties and an array of transfer listeners. You must provide the destination bucket, the S3 object key to use, and the object body.When object being uploaded is bigger than the threshold configured by
multipartUploadThresholdBytes(16MB default), S3TM breaks them down into parts, each with the part size configured bytargetPartSizeBytes(8MB default), and uploads them concurrently using S3’s multipart upload feature.Download an object
To download an object from Amazon S3, you need to provide the input struct
DownloadObjectInput, which contains the download destination, a subset ofGetObjectInputstruct properties, and an array of transfer listeners. The download destination is an instance of Swift’s Foundation.OutputStream. You must provide the download destination, the source bucket, and the S3 object key of the object to download.When object being downloaded is bigger than the size of a single part configured by
targetPartSizeBytes(8MB default), S3TM downloads the object in parts concurrently using either part numbers or byte ranges as configured bymultipartDownloadType(.partdefault).Upload a directory
To upload a local directory to a S3 bucket, you need to provide the input struct
UploadDirectoryInputand provide the destination bucket, and the source directory’s URL.The
UploadDirectoryInputstruct has several optional properties that configure the transfer behavior. For more details on what each input configuration does, refer to the documentation comments on the UploadDirectoryInput.Download a bucket
To download a S3 bucket to a local directory, you need to provide the input struct
DownloadBucketInputand provide the source bucket, and the destination directory URL.The
DownloadBucketInputstruct has several optional properties that configure the transfer behavior. For more details on what each input configuration does, refer to the documentation comments on the DownloadBucketInput.Monitor transfer progress
You can optionally configure transfer listeners for any of the S3TM operations above. The Amazon S3 Transfer Manager for Swift provides 2 canned transfer progress listeners for you. They’re
LoggingTransferListeners andStreamingTransferListeners. There’s a specific listener type for each operation, e.g.,UploadObjectLoggingTransferListeneris aLoggingTransferListenerfor the single object upload operation.The
LoggingTransferListeners log transfer events to the console using swift-log. TheStreamingTransferListeners publish transfer events to itsAsyncThrowingStreaminstance property, which can be awaited on to consume and handle events as needed. You can configure any number of transfer listeners for the S3TM operations via their inputs (e.g.,UploadObjectInput‘stransferListenersfield). You can add your own custom transfer listeners as well, by implementing a struct or a class that conforms to theTransferListenerprotocol and configuring it in the input structs.See below for the example usage of the two canned transfer listeners.
LoggingTransferListener
StreamingTransferListener
For
StreamingTransferListener, you must close the underlyingAsyncThrowingStreamafter transfer completion by explicitly callingcloseStream()on theStreamingTransferListenerinstance to prevent memory leaks and hanging stream consumers.Security
See CONTRIBUTING for more information.
License
This project is licensed under the Apache-2.0 License.