Swift 3 base64 encode image for upload
<p>I have some nice code that allows me to pic and image and then display it in app. I was also uploading the profilePic.image to my database (as a blob) but I realised that this was not actually uploading the image itself but just data about the image so I could not render anything back as there was nothing to decode. So I want to transform this function to get the chosen image and encode it to base64 and utilise same working upload </p>

<pre><code>func imagePickerController(
        _ selectImage: UIImagePickerController,
        didFinishPickingMediaWithInfo info: [String : AnyObject])
    {
        let chosenImage = info[UIImagePickerControllerEditedImage] as! UIImage //2
        // imageByCroppingToRect()
        profilePic.contentMode = .scaleAspectFit //3
        profilePic.image = chosenImage //4
        dismiss(animated: true, completion: nil) //5
    }
</code></pre>