I am implementing User Profile Module. For that I want to store the user profile, which user selected from camera or gallery. I want to pass it into the API, but I don't know how to do it.
Below is my code..
var request = URLRequest(url: URL(string: "http://xxxx.xx/UpdateEmp_test?xx=\(xx)&PermanentAddress=\(ADDrEss)&PermVillage=\(townCITY)&PermTaluk=\(taulkcode!)&PermDist=\(districtcode!)&PermPinCode=\(PINcode)&PermState=\(statecode!)&FatherName=\(FatherNaME)&MotherName=\(MothERName)&profile_image=\(imagePath)")!)
print(request)
request.httpMethod = "POST"
let session = URLSession(configuration: .default)
session.dataTask(with: request) {data, response, error in
guard error == nil && data != nil else
{
let alert = UIAlertController(title: "Check your Internet Connection", message: "", preferredStyle: .alert)
self.present(alert, animated: true, completion: nil)
let when = DispatchTime.now() + 3
DispatchQueue.main.asyncAfter(deadline: when)
{
// your code with delay
alert.dismiss(animated: true, completion: nil)
}
return
}
do
{
let json = try JSONSerialization.jsonObject(with: data!, options: [])
print(json)
let message = (json as AnyObject).value(forKey: "message") as! NSString
print(message)
DispatchQueue.main.sync {
if message == "success" {
let alert = CustomAlert(title:"Request Updated Successfully!")
alert.show(animated: true)
self.dismiss(animated: true, completion:nil)
}
else if message == "Already"{
let alert = CustomAlert(title:"Already Request Updated")
alert.show(animated: true)
}
else {
let alert = CustomAlert(title:"Failed,Try Again!")
alert.show(animated: true)
}
}
}
catch
{
}
}.resume()