简体   繁体   中英

How to get saved image file path in iOS

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?

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;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM