ios - Alamofire 4 多部分请求上传进度

标签 ios swift alamofire

我应该如何使用 Alamofire 4 跟踪我的分段上传请求的进度?

我的 encodingCompletion 处理程序:

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")
        }
}

我得到的错误是:

Cannot call value of not-function type 'Progress'

最佳答案

试试这个:

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)
            }
        }
    )

关于ios - Alamofire 4 多部分请求上传进度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39916404/

相关文章:

iphone - iPhone:如何将“yyyyMMddThhmmss”格式字符串转换为NSDate?

c++ - 粗细的画线变白,OpenCv iOS 问题

ios - 我可以在 SwiftUI 中布局后获得 `View` 的位置吗?

ios - -[NSManagedObjectContext 保存 :] 中的数组索引越界问题 (NSRangeException)

ios - 如何使用Alamofire向服务器发送参数?

swift - 使用 Alamofire 和 PromiseKit 使用 Swift 时出现 Void 错误(请求)

ios - 使用 Swift 的 SKVideoNode 中的垂直视频方向问题

ios - 推送通知不一致

ios - 从 CNContactPickerViewController 选择联系人后移动到新 View

ios - Alamofire:发送 JSON 作为请求参数