I want to upload selected image to imagePickerController with absolutely the simplest code that I can understand. (I notice answers to similar questions on stackoverflow are still quite long and not easy to understand without much explanations.) Absolute no codes that are not a must. Hence I wrote the codes below. But no files have been uploaded to my server. Does it look like there are something wrong in my codes below? Or maybe so short that I am actually missing something? Or should I cross-check my server code?
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
let photoForUpload = info[UIImagePickerController.InfoKey.originalImage] as! UIImage
var photoData = photoForUpload.jpegData(compressionQuality: 0.8)
print(type(of: photoData))
AF.upload(multipartFormData: { multipartFormData in
multipartFormData.append(photoData!, withName: "fileToUpload")
}, to: "https://www.mywebsite.com/myphpfile.php").response { response in
debugPrint(response)
}
dismiss(animated: true, completion: nil)
}