6

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'

3

2 Answers 2

22

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)
            }
        }
    )
1
  • 1
    I've posted my full implementation of the multipart upload now. Updated.
    – pedrouan
    Oct 7, 2016 at 13:05
1

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.