ALAsset, send the photo to the web service, including its exif data

I want to send a photo from a camera roll to web services, including exif data. Im using ASIFormDataRequest - so what I do:

ASIFormDataRequest *request = [[ASIFormDataRequest alloc]initWithURL:url]; 

To save memory, I directly want to send the file:

 [request addFile:localPath forKey:@"image"]; 

So, I need a local path to the resource. I think I can’t get the local path to the resource, so I temporarily save it in a file:

 ALAsset* selectedAsset = [assets objectAtIndex:index]; CGImageRef imageRef = selectedAsset.defaultRepresentation.fullScreenImage; UIImage* image = [UIImage imageWithCGImage:imageRef]; NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES); NSString *cachesDirectory = [paths objectAtIndex:0]; NSData* imageData = UIImagePNGRepresentation(image); NSString* filePath = [NSString stringWithFormat:@"%@/imageTemp.png",cachesDirectory]; [imageData writeToFile:filePath atomically:YES]; 

Then I use this path to execute

 [request addFile:localPath forKey:@"image"]; 

the image is sent to the server, but without the exif data that I need. Also, I think there should be a smarter way to do this.

TIA

+4
source share
1 answer

ok - I think I figured it out. The trick is to go with the default source data: R / P>

 ALAsset* selectedAsset = [assets objectAtIndex:index]; int byteArraySize = selectedAsset.defaultRepresentation.size; NSMutableData* rawData = [[NSMutableData alloc]initWithCapacity:byteArraySize]; void* bufferPointer = [rawData mutableBytes]; NSError* error=nil; [selectedAsset.defaultRepresentation getBytes:bufferPointer fromOffset:0 length:byteArraySize error:&error]; if (error) { NSLog(@"%@",error); } rawData = [NSMutableData dataWithBytes:bufferPointer length:byteArraySize]; NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES); NSString *cachesDirectory = [paths objectAtIndex:0]; NSString* filePath = [NSString stringWithFormat:@"%@/imageTemp.png",cachesDirectory]; [rawData writeToFile:filePath atomically:YES]; 

After using the path to send the image to the server, the file on the server stores all exif data

+10
source

All Articles