简体   繁体   中英

How get upload progress for multiple multipart upload task

i am using below code for upload progress ,but if i upload 4 images how to get progress for indiviudal upload .

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

If you have four uploads (I assume we're talking about four separate uploads and not a single request with four files uploaded), each Alamofire upload object already has its own uploadProgress property.

So, if you're using UIProgressView , you don't need to implement uploadProgress method (like you do in your example) at all, but rather just set the observedProgress of your UIProgressView to the uploadProgress property of the Alamofire upload .

Please make use of NSOperationQueue and NSOperation. You need to subclass NSOperation to perform downloading of images. Use image id or URL to distinguish image download progress. Also, you can use the block to notify the observer to update the progress.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM