I am using image picker to pick image from gallery in iPhone device. I have to save those images in the same name that is in the gallery. I don want to name it different after picking image. I tried printing the info dictionary after picking image. Its gives image,url and path and type.. but how to get the actual name of the image any idea. Following is what i get in didFinish
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
NSLog(@"Selected image info: %@",info);
}
this prints
Selected image info : (
{
UIImagePickerControllerMediaType = "public.image";
UIImagePickerControllerOriginalImage = "<UIImage: 0x617d390>";
UIImagePickerControllerReferenceURL = "assets-library://asset/asset.JPG?id=1000000089&ext=JPG";
}
)
my question is any way to get the actual name from the above.
Using the AssetsLibrary framework, you can get the referenceURL from the info dictionary and fetch the asset. Something like this:
NSURL *assetURL = [info objectForKey:UIImagePickerControllerReferenceURL];
__block NSString *fileName = nil;
ALAssetsLibrary *library = [[[ALAssetsLibrary alloc] init] autorelease];
[library assetForURL:assetURL resultBlock:^(ALAsset *asset) {
fileName = asset.defaultRepresentation.fileName;
} failureBlock:nil];
Images from picked from the gallery, DO NOT have 'names'. You never assign a name to a picture just captured from the camera and even when you add images through iTunes, the original filenames are stripped off and replaced with filenames that iTunes understands for syncing.
These filenames are not meant for programmers to access as they could be replaced by some other images in future syncs.
A good round about for this is to assign the current Date as filenames, while saving to images picked from the gallery. You may save it in your documents or library directory and use a mapping PList file to map images to their filename.
Alternatively, you can also assign unique numbers as filenames and access the images using these values.
Though you mentioned you do not want to assign new names, unfortunately, that's the only way to go about it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With