I have a fairly new project I am working on in Swift 5, and AFNetworking 4.0.1.
I am having issues with tracking progress of an upload to an API endpoint. I am building a POST command using AFHTTPSessionManager() although I have also tried this with AFURLSessionManager() and a URLSessionUploadTask, I get the same results.
The issue is once an upload has started, the progress block immediately acts like the upload is completed. Printing the output of uploadProgress.fractionCompleted, only ever prints once, and is 1.0.
I have turned on the Network Link Conditioner on my iPhone to similar a poor DSL connection, and am uploading a photo taken from the app. This takes a while before I get prints of the response from the server, but the print on the progress block is just about immediate.
Here is some of the code:
let manager = AFHTTPSessionManager()
manager.requestSerializer = AFJSONRequestSerializer()
manager.responseSerializer = AFHTTPResponseSerializer()
manager.post(
urlString,
parameters: parameters,
headers: nil,
constructingBodyWith: {
(data:AFMultipartFormData!) -> Void in
data.appendPart(withFileData: imageData!, name: "scanned_image", fileName: "image.jpg", mimeType: "image/jpeg")
},
progress: {
uploadProgress in
print(uploadProgress.fractionCompleted) // This is always called a single time
DispatchQueue.main.async(execute: {
self.progressView.progress = Float(uploadProgress.fractionCompleted)
// Progress view jumps to 100% immediately
})
},
success: {
requestOperation, response in
// Do something
},
failure: {
requestOperation, error in
// Do something with the error
}
)
Any help will be appreciated.