Uploading an image to Parse failing

爷,独闯天下 提交于 2019-12-23 04:47:32

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!