How should I track progress of my multipart upload request using Alamofire 4?
My encodingCompletion handler:
encodingCompletion: {
encodingResult in
switch encodingResult {
case .success(let uploadRequest, _, _):
uploadRequest.uploadProgress {
p in
print(p.completedUnitCount, p.totalUnitCount)
}
break
case .failure( _):
print("Failed to encode upload")
}
}
The error I get says:
Cannot call value of not-function type 'Progress'
Try this:
Alamofire.upload(
multipartFormData: { multipartFormData in
multipartFormData.append(URL(string: "http://example.com/url1")!, withName: "one")
multipartFormData.append(URL(string: "http://example.com/url2")!, withName: "two")
},
to: "http://example.com/to",
encodingCompletion: { encodingResult in
switch encodingResult {
case .success(let upload, _, _):
upload.responseJSON { response in
debugPrint(response)
}
upload.uploadProgress { progress in
print(progress.fractionCompleted)
}
case .failure(let encodingError):
print(encodingError)
}
}
)
You need to wrap the fractionCompleted
, totalUnitCount
and completedUnitCount
with a cast to Int or Float (depending on what you need).
It works!
source: https://github.com/Alamofire/Alamofire/issues/1652#issuecomment-259020449
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With