簡體   English   中英

Alamofire 4多部分請求上傳進度

[英]Alamofire 4 multipart request upload progress

如何使用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'的值

嘗試這個:

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

您需要將fractionCompletedtotalUnitCountcompletedUnitCount包裝為Int或Float(取決於您需要的內容)。

有用!

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM