开发者社区> 问答> 正文

使用Alamofire Swift在MultipartFormData中获取发布参数错误

我无法将图像上传到服务器。显示上传进度, upload.uploadProgress但之后upload.responseJSON是nil错误。我已尽力而为,但无法解决问题。请任何人都可以帮助我。我究竟做错了什么?当我调试它的{ (result) in switch result {结果无效。

邮递员密钥:( 参数)

ImageList -- for images
ProjectUnitID  -- 8568816

SWIFT代码:

if asset.type == .photo {

                    let displayImage = asset.fullResolutionImage!
                    images?.append(d)

                    let token = UserDefaults.standard.string(forKey: "newToken")

                    let image = displayImage
                    let imgData = image.jpegData(compressionQuality: 0.2)!

                    let parameters = ["ProjectUnitId": 8568816] 

                    Alamofire.upload(multipartFormData: { multipartFormData in
                            multipartFormData.append(imgData, withName: "ImageList",fileName: "file.jpg", mimeType: "image/jpg")
                            for (key, value) in parameters {
                                multipartFormData.append(value.data(using: String.Encoding.utf8)!, withName: key)
                                } 
                        },
                                     to:"http://AddProjectUnitImages", headers: [ "Authorization":"Bearer \(String(describing: token))"])
                    { (result) in
                        switch result {
                        case .success(let upload, _, _):

                            upload.uploadProgress(closure: { (progress) in
                                print("Upload Progress: \(progress.fractionCompleted)")
                            })

                            upload.responseJSON { response in
                                 print(response.result.value)
                            }

                        case .failure(let encodingError):
                            print(encodingError)
                        }
                    }


                    }

展开
收起
几许相思几点泪 2019-12-23 17:41:39 831 0
0 条回答
写回答
取消 提交回答
问答排行榜
最热
最新

相关课程

更多

相关电子书

更多
OpenStack Swift 海量小文件优化之路 立即下载
From Java/Android to Swift iOS 立即下载
Swift在Airbnb的应用实践 立即下载