0

Hi I am developing an app in which there is an option to pick the photos from iOS photo gallery. I have to upload the selected photos into the server. To upload the images i am using Kaltura SDK so i am in the situation not able to directly send the UIImage to server. i need to send saved image file path.

For that I found an solution, That is saving the selected photos in a particular file path then i will use that file path. But the problem is i do not wish to save photos again in phone memory because those photos are already stored in a particular path.

So Is there any other option to retrive the saved image file path without saving it again?

thavasidurai
  • 1,972
  • 1
  • 26
  • 51

1 Answers1

20

Try this one:

- (void)saveImage: (UIImage*)image
{
    if (image != nil)
    {
        NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
                                                         NSUserDomainMask, YES);
        NSString *documentsDirectory = [paths objectAtIndex:0];
        NSString* path = [documentsDirectory stringByAppendingPathComponent:
                      @"test.png" ];
        NSData* data = UIImagePNGRepresentation(image);
        [data writeToFile:path atomically:YES];
    } 
}

- (UIImage*)loadImage
{
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
                                                     NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString* path = [documentsDirectory stringByAppendingPathComponent:
                  @"test.png" ];
    UIImage* image = [UIImage imageWithContentsOfFile:path];
    [self sendAction:path];
    return image;
}
Kalpesh
  • 4,020
  • 4
  • 18
  • 27
Mutawe
  • 6,464
  • 3
  • 47
  • 90