Jake G
Jake G

Reputation: 1195

AWSS3TransferUtilityMultiPartUploadTask - Progress value not updated returning from background

I'm using the AWS iOS SDK to upload files to S3. I am using AWSS3TransferUtility because I want to allow background uploads.

The background task is working - a large file can successfully upload while backgrounded. The issue is, when I bring my app back to the foreground, the task.result.progress.fractionCompleted value remains at the value from before being backgrounded. And if I foreground my app before the upload is complete, the progress value will remain at that value until it is done, then jump up to 1.0.

When the app comes back to the foreground, I call enumerateToAssignBlocksForUploadTask:multiPartUploadBlocksAssigner:downloadBlocksAssigner: on my TransferUtility class, and I reassign the progress and completion handlers.

Does anyone know what may cause that value not to update? I'm not sure how to resume updating my progress bar because of this. Thanks!

Edit: Here is where I start the upload process. I have a wrapper around the AWS Task that holds onto the progress and completion handlers.

func upload(storagePath: String, sourceURL: URL, _ progressCompletion: @escaping ProgressCompletionCallback)-> UploadTask {

    let expression = AWSS3TransferUtilityMultiPartUploadExpression()
    expression.progressBlock = {(task, progress) in
        DispatchQueue.main.async(execute: {
            print("Progess: \(progress)")
            progressCompletion(false, Float(progress.fractionCompleted), nil)
        })
    }

    var completionHandler: AWSS3TransferUtilityMultiPartUploadCompletionHandlerBlock
    completionHandler = { (task, error) -> Void in
        DispatchQueue.main.async(execute: {
            print("Completed!")
            progressCompletion(true, Float(task.progress.fractionCompleted), error)
        })
    }

    let awsTask = transferUtility.uploadUsingMultiPart(fileURL: sourceURL,
                                         bucket: Constants.bucketName,
                                         key: storagePath,
                                         contentType: "text/plain",
                                         expression: expression,
                                         completionHandler: completionHandler)

    return UploadTask(task: awsTask,
                      progressBlock: expression.progressBlock!,
                      completionBlock: completionHandler)

}

Upvotes: 1

Views: 1013

Answers (1)

Rikh
Rikh

Reputation: 4232

I am facing the same issue when downloading files. Here is a link to the issue i opened on their github page, atleast for the case of downloading files. They don't receive callbacks from the NSURLSession class thats being used. It is probably something similar in your case.

Upvotes: 0

Related Questions