I'm trying to upload an image taken by the device camera, or selected from the device Gallery, later present it at the screen with an ImageView, and at last upload it to a Rest API. I already have a default image stored in the Rest API and my App is already loading this image, but when I try to change the image I have issues.

This is my code after the Post API call, the data of my JSON:

```
let defaultServiceResponse = data["defaultServiceResponse"] as! NSDictionary
            self.idResponse = defaultServiceResponse["idResponse"] as! Int
            let loginModel = LoginModel()

            if self.idResponse == 0 {

                let userInfo = data["userInfo"] as! NSDictionary
                loginModel.imageProfileUrl = userInfo["imageProfileUrl"] as! String 
                let url = URL(string: loginModel.imageProfileUrl)
                let data = try? Data(contentsOf: url!)
                self.userImage.image = UIImage(data: data!)!

```

Then I have a second class where I'm trying to upload the image: 

```
class PhotoViewController: UIViewController, UIImagePickerControllerDelegate,
UINavigationControllerDelegate {

    @IBOutlet weak var imagePicked: UIImageView!

 @IBAction func openCameraButton(sender: AnyObject) {
        if UIImagePickerController.isSourceTypeAvailable(.camera) {
            let imagePicker = UIImagePickerController()
            imagePicker.delegate = self
            imagePicker.sourceType = .camera;
            imagePicker.allowsEditing = false
            self.present(imagePicker, animated: true, completion: nil)
        }
    }

    @IBAction func openPhotoLibraryButton(sender: AnyObject) {
        if UIImagePickerController.isSourceTypeAvailable(.photoLibrary) {
            let imagePicker = UIImagePickerController()
            imagePicker.delegate = self
            imagePicker.sourceType = .photoLibrary;
            imagePicker.allowsEditing = true
            self.present(imagePicker, animated: true, completion: nil)
        }
    }

    private func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
        let image = info[UIImagePickerControllerOriginalImage] as! UIImage
        imagePicked.image = image
        dismiss(animated:true, completion: nil)
    }

    @IBAction func saveButt(sender: AnyObject) {
        let imageData = UIImageJPEGRepresentation(imagePicked.image!, 0.6)
        let compressedJPGImage = UIImage(data: imageData!)
        UIImageWriteToSavedPhotosAlbum(compressedJPGImage!, nil, nil, nil)

        let alert = UIAlertView(title: "Wow",
                                message: "Your image has been saved to Photo Library!",
                                delegate: nil,
                                cancelButtonTitle: "Ok")
        alert.show()
    }

```

When I tap the openCamara button and openLibrary button it does the correct function each time, but when I choose the photo (either from the Camera or the Gallery) it doesn't appear anything at the ImageView, and the error I receive is: "Creating an image format with an unknown type is an error
"
And I'm not sending back the image into the Rest API because I haven't any idea of how can I do that.

Can somebody help me showing where is the error that is not letting me show the picture at the screen on the ImageView?

And if it's posible can somebody show me the best way to return that image into my Rest API?