Reputation: 1759
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
Upvotes: 4
Views: 14129
Reputation: 31081
Convert your image in NSData
and then Upload this NSData
.
Your image in NSData
NSData *dataImage = UIImageJPEGRepresentation([info objectForKey:@"UIImagePickerControllerOriginalImage"],1);
Or you can convert yourImage in NSData
using
NSData *dataImage = UIImagePNGRepresentation(yourImageView.image);
For more read NSData Class Reference
Upvotes: 1
Reputation: 2451
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];
Upvotes: 13