Before Alamofire5 we could user encodingReesult of uploadRequest to get uploadProgress
.
But now after uploading Alamofire to version 5, based on Alamofire Documentation, we can use .uploadProgress
in order to get upload progress handler.
Here's my code:
AF.upload(multipartFormData: { multipartFormData in
multipartFormData.append(fileContent, withName: "file", fileName: filePath.lastPathComponent)
multipartFormData.append(token.data(using: .utf8)!, withName: "token")
}, to: uploadURL)
.uploadProgress { progress in
print(progress)
}
.responseJSON { [weak self] response in
print(response)
}
But uploadProgress
closure never called during upload progress.
I've checked many stackoverflow
questions but no one worked.
If u happen to have installed a library for network traffic debugging like Wormholy, then, checkout this issue thread. In short note, it's the issue with the library & uninstalling it, solves the problem. Not sure with other network debuggers though. To make things clear, try to playaround in a new, clean project and see if alamofire works in such environment.
replace your
.uploadProgress { progress in
print(progress)
}
with
.uploadProgress(closure: { (progress) in
print("Upload Progress: \(progress.fractionCompleted)")
})
it will give you output as :
Upload Progress: 0.035203331252732804
Upload Progress: 0.035203331252732804
Upload Progress: 0.0528049968790992
Upload Progress: 0.088008328131832
Upload Progress: 0.1584149906372976
Upload Progress: 0.2112199875163968
Upload Progress: 0.2288216531427632
Upload Progress: 0.24642331876912962
Upload Progress: 0.24642331876912962
Upload Progress: 0.24642331876912962
Upload Progress: 0.24642331876912962
Upload Progress: 0.24642331876912962
Upload Progress: 0.24642331876912962
Upload Progress: 0.24642331876912962
Edit :
AF.upload(multipartFormData: { MultipartFormData in
MultipartFormData.append(fileContent, withName: "file" , fileName: filePath.lastPathComponent , mimeType: "image/jpeg")
for(key,value) in dictonary {
MultipartFormData.append(token.data(using: String.Encoding.utf8)!, withName: "token")
}
}, to: uploadURL, method: .post, headers: ["Content-Type": "application/json")
.uploadProgress(closure: { (progress) in
print("Upload Progress: \(progress.fractionCompleted)")
})
.responseJSON{ (response) in
debugPrint("SUCCESS RESPONSE: \(response)")
}
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