My requirement is to cancel upload when ever user wishes. I'm following TransferUtility document to setup and upload video, show progress, retains state even if app is in background. I couldn't find any way to cancel the uploadTask.
{
let uploadRequest = AWSS3TransferManagerUploadRequest()
let transferUtility = AWSS3TransferUtility.default()
var completionHandler : AWSS3TransferUtilityUploadCompletionHandlerBlock?
var uploadTask : AWSTask<AWSS3TransferUtilityUploadTask>?
let expression = AWSS3TransferUtilityUploadExpression()
}
func startUpload() {
uploadTask = transferUtility.uploadFile((uploadRequest?.body)!,
bucket: (uploadRequest?.bucket)!,
key: (uploadRequest?.key)!,
contentType: "video/mov",
expression: expression,
completionHander: completionHandler).continue({ (task) -> AnyObject! in if let error = task.error {
print("Error: \(error.localizedDescription)")
}
if let _ = task.result {
}
return nil;
}) as? AWSTask<AWSS3TransferUtilityUploadTask>
}
I want to know which continue block i should use on the task and how to perform something like uploadTask.cancel() just the way we use for TransferManager task.
From the AWS documentation you should use
AWSS3TransferManagerUploadRequestas point to cancel upload request.So simply:
If you would like to cancel
AWSS3TransferUtilitytask. You should work with them directly.Use method
enumerateToAssignBlocksto fetch all activeAWSS3TransferUtilitytasks. Or directly by using methodgetUploadTasks().After you get all active upload tasks simply use
taskIdentifierof each task to find what task it is. And yes you should storetaskIdentifierof task that you would like to cancel before.Example of the cancel method.