【问题标题】:How get upload progress for multiple multipart upload task如何获取多个分段上传任务的上传进度
【发布时间】:2018-03-07 04:19:36
【问题描述】:

我正在使用以下代码进行上传进度,但如果我上传 4 张图片,如何获得个人上传进度。

Alamofire.upload(multipartFormData:{ multipartFormData in

                multipartFormData.append(data, withName: alamoName, fileName: alamoFileName, mimeType: alamoMimeType)
                for (key, value) in parameters {
                    multipartFormData.append(value.data(using: String.Encoding.utf8)!, withName: key)
                }
            },to:requestUrl){ (result) in
                switch result {
                case .success(let upload, _,_):
                    upload.uploadProgress(closure: { (progress) in
                        print("Upload Progress:%d", progress)
                    })
                    upload.responseJSON { response in
                        if(response.result.value != nil){
                            let uploadResponse = response.result.value as! Dictionary <String ,Any>
                            self.didUpdateResponse(sender: uploadResponse)
                        }
                    }
                case .failure(let encodingError):
                    print(encodingError)
                }

【问题讨论】:

标签: ios xcode swift3 alamofire


【解决方案1】:

如果您有四个上传(我假设我们谈论的是四个单独的上传,而不是一个上传四个文件的请求),每个 Alamofire upload 对象已经有自己的 uploadProgress 属性。

因此,如果您使用UIProgressView,则根本不需要实现uploadProgress 方法(就像您在示例中所做的那样),而只需设置@987654325您的UIProgressView 的@ 到Alamofire uploaduploadProgress property

【讨论】:

    【解决方案2】:

    请使用 NSOperationQueue 和 NSOperation。您需要继承 NSOperation 来执行图像下载。使用图片 id 或 URL 来区分图片下载进度。此外,您可以使用该块来通知观察者更新进度。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-03-02
      • 2017-12-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-01
      • 2014-01-05
      相关资源
      最近更新 更多