使用Alamofire上传多个数据,图像和用户数据无效

时间:2018-12-18 07:13:13

标签: ios swift alamofire alamofireimage rxalamofire

我正在注册页面。通过使用Alamofire,我尝试上载多个数据(图像和用户数据),问题出在我发出请求时,它向我显示了一条消息(消息=“发生错误”。)。我尝试了许多方法来解决它,但是没有用。我希望有人能帮助我    first image of the postman the result

 //MARK:- PARAMETERS//
    var parameters = [String: Any]()
         parameters =       ["MEM_FIRST_NAME": firstName
                            ,"MEM_LAST_NAME": lastName
                            ,"MEM_GENDER": Gender
                            ,"MEM_BIRTH_DATE": "30/06/2015"
                            ,"MEM_NATIONALITY": nationality
                            ,"MEM_OCCUPATION": jobTitle
                            ,"MEM_MOBILE": mobile
                            ,"MEM_FACEBOOK_URL" : ""
                            ,"MEM_CITY_ID": preferedCity
                            ,"MEM_EMAIL": Email
                            ,"MEM_PASSWORD": password]



//MARK:- URL
       guard let url = URL(string:"http://allonz-api.imatcheg.com/api/members/register") else {return}
        //MARK:-HEADER
         let headers: HTTPHeaders = ["Content-type":"multipart/form-data"]

        //MARK:- REQUEST
        Alamofire.upload(multipartFormData: { (form) in

        for (key, value) in parameters{
            form.append("\(value)\r\n".data(using: String.Encoding.utf8)!, withName: key as String)}
         if let data = UIImageJPEGRepresentation( photo,0.5){
            form.append(data , withName: "image", fileName: "image.png", mimeType: "image/png")}
        }
        , to: url , method: .post, headers: headers ) { (result) in

            switch result
            {
            case.failure(let error):
                print("what is the problem\(error)")
            case.success(let upload, _,_):
                upload.responseJSON(completionHandler: { respones  in
                     switch respones.result
                     {
                     case.success(let value):
                        print(value)

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

0 个答案:

没有答案