无法在Alamofire中使用multipartformdata将图像上传到服务器

时间:2020-08-07 16:12:08

标签: swift uiimageview alamofire

我尝试了很多方法,但是图像未上传到服务器

var params = [String:AnyObject]()
        params["profile_picture"] = displayPhoto.image
        AF.upload(
                
                 multipartFormData: { (multipartFormData) in

                    for (key, value) in params {
                    multipartFormData.append((value as! String).data(using:String.Encoding.utf8)!, withName: key)
                           }
                    if let imageData = self.displayPhoto.image?.jpegData(compressionQuality: 0.5) {
                     multipartFormData.append(imageData, withName: "profile_picture", fileName: "file.jpeg", mimeType: "image/jpeg")
                           }

 }, to: "http://ms.XXX/regester",usingThreshold: UInt64.init(),method: .post,headers: nil).responseJSON{
                                   response in
                                   switch response.result {
                                   case .success:
                                    print(response)
                                     let vc = UIStoryboard.init(name: "Main", bundle: Bundle.main).instantiateViewController(withIdentifier: "homeVC") as? HomeVC
                                            self.navigationController?.pushViewController(vc!, animated: true)
                                          break
                                   case .failure(let error):
                                       print(error)
                                       break
                                   }}
        

我尝试了很多stackoverflows方法,但无法解决问题请澄清我的错误 我从图库中选择图片

0 个答案:

没有答案