问题
I am unable to save a image captured and send it up to my mongodb using Parse. I am not sure what my error is related to. I definitely have the image capturing part correct using my imagePickerController.
Here's my code:
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
if let image = info[UIImagePickerControllerOriginalImage] as? UIImage {
print("Did finish picking media. Image \(image)")
let imageData = UIImagePNGRepresentation(image)
let imageFile = PFFile(name:"image.png", data:imageData!)
let pohto_object = PFObject(className: "UserPhoto")
pohto_object["imageName"] = "My trip to Hawaii!"
pohto_object["imageFile"] = imageFile
pohto_object.saveInBackground() { (success, error) -> Void in
if error == nil {
print("Saved in server")
} else {
print("did not save because: \(error!)")
}
}
print ("the object is \(pohto_object)")
} else {
print("Did finish picking media. Image is nil")
}
dismiss(animated: true)
}
This is my output in console:
Did finish picking media. Image <UIImage: 0x17468ac30> size {3024, 4032} orientation 3 scale 1.000000
libc++abi.dylib: terminating with uncaught exception of type NSException
回答1:
So my problem was solved by changing from UIImagePNGRepresentation to UIImageJPEGRepresentation as indicated by Leo
来源:https://stackoverflow.com/questions/46820229/uploading-an-image-to-parse-failing