0

在我的项目中,我使用的是 Alamofire 5.9.3,以下是将数据上传到服务器。

    APISessionController.sharedInstance.sessionManager().upload(multipartFormData: { (multipartFormData) in
            
            for (key, value) in parameters {
                multipartFormData.append(value.data(using: String.Encoding.utf8)!, withName: key)
            }
        }, to:url)
        { (result) in
            switch result {
                
            case .success(let upload, _, _): // Getting Error: '_' can only appear in a pattern or on the left side of an assignment
                upload.uploadProgress(closure: { (Progress) in
                        self.delegate.uploadProgress(Progress.fractionCompleted)
                })
                
                upload.responseJSON { response in
                    if let JSON = response.result.value as? Dictionary<String, AnyObject> {
}

            case .failure(_): //Getting Error : '_' can only appear in a pattern or on the left side of an assignment

Previoulsy 我使用的是 Alamofire 4.9.1,它工作正常。但它在 Alamofire 5 中显示错误?

4

1 回答 1

0

Alamofire 的分段上传 API 在 Alamofire 5 中发生了变化。不再需要编码完成闭包,您可以使用普通的 Alamofire API。

APISessionController.sharedInstance.sessionManager().upload(multipartFormData: { (multipartFormData) in
            
            for (key, value) in parameters {
                multipartFormData.append(value.data(using: String.Encoding.utf8)!, withName: key)
            }
        }, to:url)
  .uploadProgress { }
  .response { }
于 2021-06-01T16:03:00.407 回答