0

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];
}
rmaddy
  • 314,917
  • 42
  • 532
  • 579
sumi
  • 3
  • 4
  • 1
    I'm not quite sure what you are asking for. Where do you want to _upload_ the file to - to a web server? Wher edo you need a path? Please show us more code. – Andreas Oetjen Jun 08 '18 at 06:04
  • I was asking I am creating gallery in my app and need to upload photo from iphone and that photo needs to save in gallery in app ,so my parameter is image path to upload image on server ..i have not mention any path of image ,plz help me – sumi Jun 08 '18 at 08:31
  • Check this: https://stackoverflow.com/questions/26335656/how-to-upload-images-to-a-server-in-ios-with-swift (or search for "upload uiimage" in this forum). The main idea is to create an jpeg (or png or whatever) representation out of your `chosenImage` and upload this as multipart content. – Andreas Oetjen Jun 08 '18 at 10:54

1 Answers1

0

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!

MS_iOS
  • 401
  • 1
  • 5
  • 13