在我的Swift应用程序中,我可以通过AWS SDK将图像上传到我的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
}
即使我在上传完成之前关闭了视图,如何才能将其上传到后台?