Hi, is there any way to possible upload an image using
request.httpMethod = "FILES"
so i have this code for Select the photo from carrier "photos in Iphone"
but i haven't found the way to store the photo or named it, i only can display it, so i can send it like any other UITextField.text 'info' using my PHP code
@IBAction func SelectPhoto(_ sender: UIButton) {
let imageController = UIImagePickerController()
imageController.delegate = self
imageController.sourceType = UIImagePickerController.SourceType.photoLibrary
self.present(imageController, animated: true, completion: nil)
}
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
image.image = info[UIImagePickerController.InfoKey.originalImage] as? UIImage //display it on UIimageview
self.dismiss(animated: true, completion: nil)
}
this is my code for Upload the photo i'm sending it using request.httpMethod = "FILES"
@IBAction func uploadPhoto(_ sender: UIButton) {
let request = NSMutableURLRequest(url: NSURL(string: "hehe")! as URL)
request.httpMethod = "FILES"
let postString = "Foto=\(!)" // user must choose the photo from carrier
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()
}
is there any way possible to send it using that method? or should i quit programming help plz 😟