应用程序在AWS S3存储桶中的上传映像中崩溃,用于swift 3

时间:2017-02-10 05:47:40

标签: ios amazon-s3 swift3 aws-sdk

在我的应用程序中,我正在尝试使用AWS S3上传图像。但是,当我从库或捕获的图像中选择图像时,在上传过程中我的应用程序正在崩溃。

let path:NSString = (NSTemporaryDirectory() as NSString).appendingPathComponent("testImage.png") as NSString
let imageData:NSData = UIImagePNGRepresentation(image)! as NSData
imageData.write(toFile: path as String, atomically: true)
let url:NSURL = NSURL(fileURLWithPath: path as String)
let expression = AWSS3TransferUtilityUploadExpression()
expression.setValue("public-read", forRequestParameter: "x-amz-acl")
expression.setValue("public-read", forRequestHeader: "x-amz-acl" )
let transferUtility = AWSS3TransferUtility.default()

transferUtility.uploadFile(url as URL!, bucket: bucketURL, key: myImageUploadKey , contentType: "image/png", expression: expression, completionHandler: { (task, error) in

if error != nil{
print(error?.localizedDescription ?? "error")
}else{
print(task.response ?? "Response error")
}
})

expression.progressBlock = { (task: AWSS3TransferUtilityTask, progress: Progress) in
print("progress \(progress.fractionCompleted)")
}

应用程序正在崩溃,因为transferUtility = AWSS3TransferUtility.default()

所以请建议任何解决方案。非常感谢。谢谢。

1 个答案:

答案 0 :(得分:0)

由于AWS S3 pod更新,可能会出现此问题。请检查最新的豆荚。请查看此https://github.com/aws/aws-sdk-ios