使用swift 3将图像上传到S3

时间:2017-03-17 01:34:09

标签: ios amazon-web-services amazon-s3 swift3

好吧,我一直在寻找一个星期的高低,现在无济于事。有人可以指导我更新swift 3的S3上传教程吗?我现在还不擅长关注文档(对于iOS来说仍然很新),我发现的所有内容都是预先快速3,我无法解决所有错误。

我甚至愿意付钱给别人用skype教我什么东西,事实上我更喜欢它...任何帮助/建议都非常感谢......

1 个答案:

答案 0 :(得分:1)

你可以参考这个样本:

https://github.com/awslabs/aws-sdk-ios-samples/tree/master/S3TransferUtility-Sample/Swift

以上示例中的摘录和重要部分:

SDK初始化:

将其复制到info.plist中:

https://github.com/awslabs/aws-sdk-ios-samples/blob/master/S3TransferUtility-Sample/Swift/S3BackgroundTransferSampleSwift/Info.plist#L73

上传代码:

let transferUtility = AWSS3TransferUtility.default()
let expression = AWSS3TransferUtilityUploadExpression()
expression.progressBlock = progressBlock

transferUtility.uploadData(
            data,
            bucket: S3BucketName,
            key: S3UploadKeyName,
            contentType: "image/png",
            expression: expression,
            completionHandler: completionHandler).continueWith { (task) -> AnyObject! in
            if let error = task.error {
                print("Error: \(error.localizedDescription)")
                self.statusLabel.text = "Failed"
            }

            if let _ = task.result {
                self.statusLabel.text = "Generating Upload File"
                print("Upload Starting!")
                // Do something with uploadTask.
            }

            return nil;
    }