Where to save image path i am uploading image for the gallery and need to pass the image path as a parameter
- (IBAction)chooseFileBtn:(id)sender {
// For picking image from gallery
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentViewController:picker animated:YES completion:nil];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
// output image
UIImage *chosenImage = info[UIImagePickerControllerEditedImage];
//self.profileImageView.image = chosenImage;
[picker dismissViewControllerAnimated:YES completion:nil];
}
Get the path of the image chosen from library using the following code in using Image Picker ViewController:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
[picker dismissModalViewControllerAnimated:YES];
NSURL *imagePath = [info objectForKey:@"UIImagePickerControllerReferenceURL"];
NSString *imageName = [imagePath lastPathComponent];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *localFilePath = [documentsDirectory stringByAppendingPathComponent:imageName];
NSLog(@"localFilePath.%@",localFilePath);
}
For uploading this path to server as a parameter you can create a multipart/form-data request as in (POST multipart/form-data with Objective-C) I hope it solves your issue.Happy coding!