IOS - loading image with EXIF ​​without changes

I have images saved in the My Documents folder in .jpg format with EXIF ​​data. My problem is that whenever I try to convert .jpg files to NSData for upload using HTTP POST, the uploaded image loses all its EXIF ​​data.

 NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsPath = [paths objectAtIndex:0]; NSString *imagePath = [documentsPath stringByAppendingPathComponent:[NSString stringWithFormat:@"%@",imageName]]; NSData *jpegImageData = [NSData dataWithContentsOfFile:imagePath]; 

How can I download my .jpg files from the document directory with their EXIF ​​intact?

+5
source share
1 answer

Save metadata of EXIF ​​jpg file. I worked with a solution:

 - (void)uploadImage:(NSString *)imagePath { dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{ // Repair upload data UIImage *image = [UIImage imageNamed:imagePath]; NSData *rawDataImage = UIImageJPEGRepresentation(image, 1.0f); NSString *base64EncodedString = @""; if ([rawDataImage respondsToSelector:@selector(base64EncodedStringWithOptions:)]) { base64EncodedString = [rawDataImage base64EncodedStringWithOptions:0]; } else { base64EncodedString = [rawDataImage base64Encoding]; } NSString *uploadBody = [NSString stringWithFormat:@"{\"imageData\": \"%@\"}", base64EncodedString]; // Post uploadBody to server NSString *serverUrl = @"Your_server"; NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:serverUrl]]; [request addValue:@"application/json; charset=utf-8" forHTTPHeaderField:@"Content-Type"]; NSString *msgLength = [NSString stringWithFormat:@"%lu", uploadBody.length]; [request addValue:msgLength forHTTPHeaderField:@"Content-Length"]; [request setHTTPMethod:@"POST"]; [request setHTTPBody:[uploadBody dataUsingEncoding:NSUTF8StringEncoding]]; [NSURLConnection connectionWithRequest:request delegate:<your_delegate OR nil>]; }); } 

Hope this helps you.

+1
source

All Articles