1

Within my Swift app, I am able to upload an image to my S3 bucket through the AWS SDK. Right now, I have to wait until the file has successfully uploaded before dismissing the view.

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
    }

How can I get this to work so that it uploads to the background even if I dismiss the view before the upload is complete?

Katie H
  • 2,283
  • 5
  • 30
  • 51

0 Answers0