Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get the path of the image which is in iphone gallery

i need to upload a image from iphone gallery ,but i am not getting the path of the picked image (using image picker)

in the image picker delegate method i am doing the following

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
    [picker dismissModalViewControllerAnimated:YES];
    imageView.image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];

    NSString *strImagePath = [info valueForKey:UIImagePickerControllerReferenceURL];
    NSString *strImagePath1 = [info valueForKey:UIImagePickerControllerMediaURL];
    NSLog(@"%@",strImagePath);
    NSLog(@"%@",strImagePath1);
    NSLog(@"%@",info);

}

and the info dictionary contains following key values

{
    UIImagePickerControllerMediaType = "public.image";
    UIImagePickerControllerOriginalImage = "<UIImage: 0x16adc0>";
    UIImagePickerControllerReferenceURL = "assets-library://asset/asset.PNG?id=1000000153&ext=PNG";
}

i used the value for key UIImagePickerControllerReferenceURL as the image path to upload it to FTP but i couldnt upload the file, probably the path which i taking is incorrect.

can anybody help me out how can i take the actual path of the picked image using image picker

like image 978
Ravi Avatar asked Dec 09 '22 19:12

Ravi


1 Answers

May be it will helpful for u

[picker dismissModalViewControllerAnimated:YES];
imageView.image= [info objectForKey:@"UIImagePickerControllerOriginalImage"];
NSData *webData = UIImagePNGRepresentation(imageView.image);
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *localFilePath = [documentsDirectory stringByAppendingPathComponent:png];
[webData writeToFile:localFilePath atomically:YES];
NSLog(@"localFilePath.%@",localFilePath);

UIImage *image = [UIImage imageWithContentsOfFile:localFilePath];
like image 123
Sudha Tiwari Avatar answered Dec 11 '22 09:12

Sudha Tiwari