In my app I have a feature to take a picture from camera
and upload it to server. My problem is that when I'm getting response back from server that image is rotating to 90 degree left side. Here is my tried code:
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any])
{
self.PickerFrom = self.PickerFrom2
if let pickedImage = info[UIImagePickerControllerOriginalImage] as? UIImage
{
self.AttachmentImageView.image = pickedImage
}
dismiss(animated: true, completion: nil)
uploadGalleryImage(image: self.AttachmentImageView.image!)
}
func uploadGalleryImage( image:UIImage)
{
let imageData: NSData = UIImagePNGRepresentation(image)! as NSData
let base64String = imageData.base64EncodedString(options: NSData.Base64EncodingOptions(rawValue: 0))
self.AttachedDocumentURL = "data:image/png;base64,\(base64String)"
}
AttachedDocumentURL
contains base64sting of captured image.
Try this (reset you image orientation) before you upload on server
Use this common function to fix upside image orientation from any.
Swift 4.1 compatible. This extension avoids sending image exif data on the iOS device side.