Once try like this,
- (void)imagePickerController:(UIImagePickerController *)imagePicker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
NSURL *videoUrl = (NSURL *)[info objectForKey:UIImagePickerControllerMediaURL];
NSDate *now = [NSDate date];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
dateFormatter.dateFormat = @"hh:mm:ss";
[dateFormatter setTimeZone:[NSTimeZone systemTimeZone]];
NSData *videoData = [NSData dataWithContentsOfURL:videoUrl];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *savedvedioPath = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"%@",[dateFormatter stringFromDate:now]]];
savedvedioPath = [savedvedioPath stringByAppendingFormat:@".mp4"];
[videoData writeToFile:savedvedioPath atomically:NO];
//here is the method to upload onto server
[self Upload_server:savedvedioPath];
[self dismissModalViewControllerAnimated:YES];
}
now define your method to upload vedio like,
-(void)Upload_server:(NSString*)file_path {
NSURL *url = [NSURL URLWithString: @"YOUR_URL_TO_UPLOAD"];
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
[request setUseKeychainPersistence:YES];
[request addFile:file_path forKey:@"YOUR_KEY"];
//insted of in above line you can also use [request setData:vedioData withFileName:@"your_file_name" andContentType:@"video/mp4" forKey:@"YOUR_KEY"] by Sending vedioData of type NSData as another perameter to this method.
[request setDelegate:self];
[request setDidFinishSelector:@selector(uploadRequestFinished:)];
[request setDidFailSelector:@selector(uploadRequestFailed:)];
[request startAsynchronous];
}
now implement ASIFormDataRequest delegatemethods like,
- (void)uploadRequestFinished:(ASIHTTPRequest *)request{
NSString *responseString = [request responseString];
//do something after sucessful upload
}
- (void)uploadRequestFailed:(ASIHTTPRequest *)request{
NSLog(@" Error - Statistics file upload failed: \"%@\"",[[request error] localizedDescription]);
}
Here i took ASIFormDataRequest to upload on to server.hope it will hepls you..