0

I'm working on register page. by using Alamofire , I'm trying to upload multiple data (image and user data ), the problem is here when I make the request, It shows to me this a message (Message = "An error has occurred."). I have tried many ways to solve it but did not work. I hope some one help me 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)
                    }
                })
            }
        }
    }
    }
  • I suggest you to first try this in **POSTMAN**. If you still face that error in **POSTMAN** then there's problem from api side otherwise there's problem from your end. – Kuldeep Dec 18 '18 at 07:16
  • I have tried in POSTMAN it's worked perfect but when I tried it in the Xcode shows to me this error message –  Dec 18 '18 at 07:18
  • Hi @Sekiz, Check this link. Its gonna work https://stackoverflow.com/questions/53650584/swift-4-get-an-upload-image-progress-using-urlsession/53650851#53650851 – Abdul Hoque Nuri Dec 18 '18 at 07:24
  • @Sekiz, can you please upload your postman response screenshot because I have tried your request in POSTMAN and it gives me same error that you mentioned. – Kuldeep Dec 18 '18 at 07:27
  • @kuldeep I have updated the question with the links of the images form POSTMAN –  Dec 18 '18 at 07:43

0 Answers0