I currently have a JPEG image saved in my app folder with its correct orientation. I need to compress and copy that image to a temporary folder and then send the URL to S3, the way I'm doing it works but the image loses its rotation attribute.
This is what I have:
//I retrieve the image
PHImageManager.defaultManager().requestImageForAsset(p, targetSize: PHImageManagerMaximumSize, contentMode: .AspectFill, options: nil, resultHandler: {(result, info)in
//Create temp url
let testFileURL = NSURL(fileURLWithPath: NSTemporaryDirectory().stringByAppendingPathComponent("temp"))
//Compress the image, I think is here where the orientation is lost
let data = UIImageJPEGRepresentation(result, 0)
//Write the image to the tmp folder, or maybe it is here where is lost
data.writeToURL(testFileURL!, atomically: true)
//Send URL to upload to S3
self.uploadImagesToS3(testFileURL!, picName: p.valueForKey("filename") as String, deviceID: deviceID, length: data.length)
})
Anybody has an idea of what can I do?. The image has the right orientation before the compression and copy, but is rotated after that. The image is taken from the camera.
Thank you!.