I need to check whether the image is nil or not which i assigned as one of the [key, value] pair in the dictionary. I need to send the dictionary as a parameter in Alamofire Post Method. But i couldn't pass the parameter. I will show what i have done. Clarify me what i did wrong! and give me the solution.
var parameters: [String : AnyObject ] = [
"email" : "123@gmail.com",
"password" : "password",
"full_name": "XXX",
"profile_pic" : UIImage(named: "abc")!
]
Alamofire.upload(
.POST,
"http://abc/public/user/register",
multipartFormData: { multipartFormData in
for (key, value) in parameters {
multipartFormData.appendBodyPart(data: value.dataUsingEncoding(NSUTF8StringEncoding)!, name: key)
}
},
encodingCompletion: { encodingResult in
switch encodingResult {
case .Success(let upload, _, _):
upload.responseJSON { response in
debugPrint(response)
}
case .Failure(let encodingError):
print(encodingError)
}
}
)
I encounter an error says, unrecognized selector sent to an instance I would like to get the successful response back even if the profile_pic is nil or not. I get the success response if i append the image like this
multipartFormData.appendBodyPart(fileURL: unicornImageURL, name: "unicorn")
.
The end result is that, the response should say that the user registration is successful even if he uploads the profile picture or not. Because it is an optional field right?!