【问题标题】:Alamofire 4 multipart request upload progressAlamofire 4 分段请求上传进度
【发布时间】:2017-02-16 09:41:08
【问题描述】:

我应该如何使用 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")
        }
}

我得到的错误是:

不能调用非函数类型'Progress'的值

【问题讨论】:

标签: ios swift alamofire


【解决方案1】:

试试这个:

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

【讨论】:

  • 我现在已经发布了分段上传的完整实现。已更新。
【解决方案2】:

您需要将 fractionCompletedtotalUnitCountcompletedUnitCount 转换为 Int 或 Float(取决于您的需要)。

有效!

来源:https://github.com/Alamofire/Alamofire/issues/1652#issuecomment-259020449

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-02-22
    • 1970-01-01
    • 1970-01-01
    • 2014-12-17
    • 2018-11-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多