Hi, So when the user fill all his data he must select a photo from carrier (photos)
@IBAction func selecFoto(_ sender: UIButton) {
//select photo from carrier
let imageController = UIImagePickerController()
imageController.delegate = self
imageController.sourceType = UIImagePickerController.SourceType.photoLibrary
self.present(imageController, animated: true, completion: nil)
}
//display it on UIVIEW
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
image.image = info[UIImagePickerController.InfoKey.originalImage] as? UIImage
self.dismiss(animated: true, completion: nil)
}
So the user's photo is named 'image'
image converts into base64
*note this code is before the UIbutton action *
class func convertImageToBase64(image: UIImage) -> String {
let imageData = UIImagePNGRepresentation(image)!
return imageData.base64EncodedString(options: Data.Base64EncodingOptions.lineLength64Characters) }
so and sends into my database
@IBAction func crearCuenta(_ sender: UIButton) {
if nombreConductor.text == "" || email.text == "" || password.text == "" || confirmarpass.text == "" || telefono.text == "" || telefonoContacto.text == "" || emailContacto.text == "" || ciudad.text == "" || direccion.text == "" || matricula.text == "" || licencia.text == "" || numeroTaxi.text == "" || tipoVehiculo.text == "" || year.text == "" || marcaCarro.text == "" {
displayAlert(title: "Información Faltante", message: "Debes porporcionar los datos solicitados")
}
if password.text != confirmarpass.text {
displayAlert(title: "Usuario", message: "Las contraseñas no coinciden")
}
else{
let request = NSMutableURLRequest(url: NSURL(string: "hehe")! as URL)
request.httpMethod = "POST"
let postString = "Nombre_Completo=\(nombreConductor.text!)&Correo=\(email.text!)&Password=\(password.text!)&Telefono=\(telefono.text!)&Email_Contacto=\(emailContacto.text!)&Telefono_Contacto=\(telefonoContacto.text!)&Nivel=\(nivel)&Ciudad=\(ciudad.text!)&Direccion=\(direccion.text!)&Matricula=\(matricula.text!)&Licencia=\(licencia.text!)&N_Taxi=\(numeroTaxi.text!)&Tipo_Vehiculo=\(tipoVehiculo.text!)&Marca_Vehiculo=\(marcaCarro.text!)&Year=\(year.text!)&Foto=\(image!)"
request.httpBody = postString.data(using: String.Encoding.utf8)
let task = URLSession.shared.dataTask(with: request as URLRequest) {
data, response, error in
if error != nil {
print("error=\(String(describing: error))")
return
}
print("response = \(String(describing: response))")
let responseString = NSString(data: data!, encoding: String.Encoding.utf8.rawValue)
print("responseString = \(String(describing: responseString))")
}
task.resume()
}
}
i get this response from the console
*which is true and sends sucessfully the data to the DB, but not the Image*
response = Optional( { URL: hehe } { Status Code: 200, Headers {
"Content-Encoding" = (
gzip
);
"Content-Type" = (
"text/html; charset=UTF-8"
);
Date = (
"Fri, 26 Oct 2018 18:24:15 GMT"
);
Server = (
Apache
);
"x-powered-by" = (
"PHP/5.6.38"
);
} })
responseString = Optional({"Response":"true"}) //true
and this is what my DB gets on the image Field
<UIImageView: 0x147d0d7d0; frame = (93 1502; 188 83); opaque = NO; autoresize = RM BM; userInteractionEnabled = NO; layer = <CALayer: 0x2816f2820>>
any ideas?