views:

563

answers:

2

In my application, the user can record a video using the UIImagePickerController, and I need to save it to disk for later use. I've gotten the path out of the info dictionary and I'm going to save it to my documents directory, but the problem I'm having is that the URL passed in the dictionary is just that - a URL and not a file path. When I convert it to a string using absoluteString and pass that as the source path to my file manager, it fails saying the source file wasn't found.

Old Path: file://localhost/private/var/mobile/Applications/77B4D2B8-DE12-4643-82F0-2ECC948E4DBC/tmp/capture/capturedvideo.MOV

New Path: /var/mobile/Applications/77B4D2B8-DE12-4643-82F0-2ECC948E4DBC/Documents/video1.mov

There's got to be an easy way to convert my URL to something the file manager can handle. I'm guessing I can't just leave all the videos in the tmp directory, they must be saved to the documents directory if I want to keep them around right?

Also, this isn't really related, but how might I get a thumbnail of that video to show in a table view?

+2  A: 

There's got to be an easy way to convert my URL to something the file manager can handle.

You're right -- there is an easy way, it's just buried in the documentation:

NSString *myPath = [myUrl path];

From the docs for the path method:

Return Value
The path of the URL. If the receiver does not conform to RFC 1808, returns nil. If isFileURL returns YES, the return value is suitable for input into NSFileManager or NSPathUtilities. If the path has a trailing slash it is stripped.

Steve Losh
Helped me, thanx.
Raj
A: 

NSData *imageData = [NSData dataWithContentsOfURL:[info objectForKey:@"UIImagePickerControllerMediaURL"]];

NSString *tempPath = [NSString stringWithFormat:@"%@/Documents/%@.mp4",NSHomeDirectory(),dateStr];

[imageData writeToFile:tempPath atomically:NO];