self.manager.upload(multipartFormData: { multipartFormData in
if let imageData = UIImageJPEGRepresentation(file, 0.6) {
multipartFormData.append(imageData, withName: "upload", fileName: "jpeg", mimeType: "image/jpeg")
}
multipartFormData.append(xxx.data(using: String.Encoding.utf8, allowLossyConversion: false)!, withName :"xxx")
multipartFormData.append(xxx.data(using: String.Encoding.utf8, allowLossyConversion: false)!, withName :"xxx")
multipartFormData.append(xxx.data(using: String.Encoding.utf8, allowLossyConversion: false)!, withName :"xxx")
multipartFormData.append(xxx.data(using: String.Encoding.utf8, allowLossyConversion: false)!, withName :"xxx")
}, to: "http://example.com/r", encodingCompletion: { encodingResult in
switch encodingResult {
case .success(let upload, _, _):
upload.uploadProgress{(progress: Progress) in
reqProgress(progress.fractionCompleted)
}
upload.responseJSON { response in
switch response.result {
case .success(let JSON):
guard let response = JSON as? [AnyObject] else{
completion(nil)
return
}
completion(response)
case .failure( _):
completion(nil)
}
}
case .failure(let encodingError):
completion(nil)
}
})
upload.uploadProgress gives me error:
Cannot call value of non-function type 'Progress'
Not completely sure what you're getting bit by since I don't have a full file to compile. I'd guess you need to import Foundation or remove the Progress declaration like this:
upload.uploadProgress { progress in
print(progress)
}
Other than that I'd suggest you compile out parts of your declaration and slowly add it back in to find your mistake. We have all sorts of tests around this in the test suite that don't have the issue.
Best of luck! 馃嵒
@GZaccaroni Did you ever figure this out? I've run into this issue and can't figure out what's going on.
From what I've read, Request has a conflicting progress field? I found a lot of people with the same issue, and I wonder if this should be opened and addressed? The MultipartFormData example should maybe show the correct usage of .uploadProgress in the encodingCompletion closure.
Related discussions/issues:
https://github.com/Alamofire/Alamofire/issues/679#issuecomment-222371221
https://github.com/Alamofire/Alamofire/issues/989#issuecomment-251508846
Discussing v3: http://stackoverflow.com/a/39075334/1575489
I don't understand why, but this works:
.uploadProgress { progress in
self.ProgressBar.progress = Float(progress.fractionCompleted)
}
And this gives the Cannot call value of non-function type 'Progress' compiler error:
.uploadProgress { progress in
self.ProgressBar.setProgress(Float(progress.fractionCompleted), animated: true)
}
@rudedogg For me:
This doesn't work:
.uploadProgress { progress in
self.progressBar.setProgress(progress.fractionCompleted, animated: true)
}
This works:
.uploadProgress { progress in
self.progressBar.setProgress(Float(progress.fractionCompleted), animated: true)
}
Strange bug.
`Alamofire.upload(
multipartFormData: { multipartFormData in
if let imageData = UIImageJPEGRepresentation(image, 0.5) {
multipartFormData.append(imageData, withName:imageType ,fileName: "file", mimeType: "image/jpeg")
}
for (key, value) in parameter {
multipartFormData.append(String(describing: value).data(using: .utf8)!, withName: key)
}
}, to: url, method: .put, headers:headers,
encodingCompletion: { encodingResult in
switch encodingResult {
case .success(let upload, _, _):
.uploadProgress{ progress in
ProgressBar.setProgress(Float(progress.fractionCompleted), animated: true)
}
upload.responseJSON { response in
debugPrint(response)
let statusCode = response.response?.statusCode
var errorMessage = ""
if((response.result.error != nil)) {
errorMessage = (response.result.error?.localizedDescription)!
}
var status = false
status = true
if(statusCode == 200) {
}
completion(status, statusCode!, errorMessage)
}
case .failure(let encodingError):
print(encodingError)
completion(false, 500, "error")
}
}
)
`
For Alamofire I'm Using Object mapper so how I'm create on class file and use in my view controller swift file..??
Most helpful comment
I don't understand why, but this works:
And this gives the
Cannot call value of non-function type 'Progress'compiler error: