在我的 Swift 应用程序中,我可以通过 AWS 开发工具包将图像上传到我的 S3 存储桶。现在,我必须等到文件成功上传后才能关闭视图。
let transferManager = AWSS3TransferManager.defaultS3TransferManager()
let testFileURL1 = NSURL(fileURLWithPath: NSTemporaryDirectory().stringByAppendingPathComponent("temp"))
let uploadRequest1 : AWSS3TransferManagerUploadRequest = AWSS3TransferManagerUploadRequest()
let data = UIImageJPEGRepresentation(image, 0.5)
data.writeToURL(testFileURL1!, atomically: true)
uploadRequest1.bucket = "shrikar-picbucket"
uploadRequest1.key = "bingo"
uploadRequest1.body = testFileURL1
let task = transferManager.upload(uploadRequest1)
task.continueWithBlock { (task) -> AnyObject! in
if task.error != nil {
println("Error: \(task.error)")
} else {
println("Upload successful")
self.dismissViewControllerAnimated(true, completion: nil)
}
return nil
}
即使我在上传完成之前关闭视图,我怎样才能让它工作,以便它上传到后台?