0

In my app I am taking a picture and showing it in an image view.

Now I need the path of that image so I can upload it to a server.

How do I get that path? I try importing ALAsset framework but there is no framework called that my x code (4.2) iOS 5.0

NSData *data = UIImagePNGRepresentation(imagePic.image);
NSString *file = [NSTemporaryDirectory() stringByAppendingPathComponent:@"upload.jpg"];

[data writeToFile:file atomically:YES]; 

[[EPUploader alloc] initWithURL:[NSURL URLWithString:@"myWebSite"]
                       filePath:@"file"
                       delegate:self
                   doneSelector:@selector(onUploadDone:)
                  errorSelector:@selector(onUploadError:)]; 

This is what I am currently trying.

Also what would be a hard coded path to a photo in an iphone camera roll? "iphone/pictures/myPic" ?? so I can try the upload separate from finding the path.

Please and Thank you

EDIT:

- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
// Access the uncropped image from info dictionary
image2 = [info objectForKey:@"UIImagePickerControllerOriginalImage"];

// Save image
UIImageWriteToSavedPhotosAlbum(image2, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);
imagePic.image = image2;
[picker release];
}
3
  • 1
    wait why cant you just use the file variable that contains the path where you just saved the image? Commented Apr 26, 2012 at 20:51
  • you mean "file" for the nsdata of when i save it after i take the pic. I really don't want to save the photo at all in the end but i can its no biggie Commented Apr 26, 2012 at 20:57
  • yeah that would work, you need to save it somewhere to have a path otherwise its only in memory. Commented Apr 26, 2012 at 23:16

1 Answer 1

3

An image view has no path, it's in memory. You'll have to save the path you get when you return from taking the image. In the delegate method imagePickerController:didFinishPickingMediaWithInfo: you can get the NSURL in UIImagePickerControllerMediaURL which points to the image on disk:

NSURL *imageURL = [info valueForKey:UIImagePickerControllerMediaURL];
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.