0

I want to send image to server for it i am displaying PhotoLibrary from UIImagePickerController

Whenever user selects any photo from ImagePicker i pick up url of image.

but it shows in the format of assets-library which i don't want (Output of my log) localUrl =assets-library://asset/asset.JPG?id=106E99A1-4F6A-45A2-B320-B0AD4A8E8473&ext=JPG

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
    [picker dismissViewControllerAnimated:YES completion:^{

        NSURL* localUrl = (NSURL *)[info valueForKey:UIImagePickerControllerReferenceURL];
        NSLog(@"localUrl =%@",localUrl);

    }];

}

I want it to be in the format of file:///Users/Library/Developer/CoreSimulator/Devices/85CBED11-A318-4096-B52A-EBC3879F7B34/data/Containers/Data/Application/805BB62D-E32E-4D1E-99B6-C91103A1D99B/tmp/testing.doc

How do i achieve this?

Please help and thanks in advance!

Krunal
  • 6,440
  • 21
  • 91
  • 155
  • Possible duplicate of [Access Asset Catalog pathForResource](http://stackoverflow.com/questions/18968352/access-asset-catalog-pathforresource) – shallowThought Dec 14 '16 at 13:58

1 Answers1

0

I have no idea why you need to do this case. but you can try it.

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
    [picker dismissViewControllerAnimated:YES completion:^{    
       NSData *pngData = UIImagePNGRepresentation(ivPickedImage.image);
       NSArray *paths =  NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
       NSString *documentsPath = [paths objectAtIndex:0]; //Get the docs directory
       NSString *filePath = [documentsPath stringByAppendingPathComponent:@"image.png"]; //Add the file name
      [pngData writeToFile:filePath atomically:YES]; //Write the file
       NSLog(@"localUrl =%@",filePath);
    }];
}
Tommy Li
  • 90
  • 6