tags:

views:

46

answers:

2

Hi. I am working on one app in which i need to upload video and audio, i had heard lot about mediapicker but i am not getting actually how to deal with it. Can anyone please tell me about this.

A: 

NSString *urlString = [NSString stringWithFormat:@"http://www.example.com/uploadvideoxml.php?user_id=%@",[vedioDict valueForKey:@"user_id"]];

NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];

[request setURL:[NSURL URLWithString:urlString]];

[request setHTTPMethod:@"POST"];

NSString *boundary = [NSString stringWithString:@"---------------------------14737809831466499882746641449"];

NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@",boundary];

[request addValue:contentType forHTTPHeaderField: @"Content-Type"];

NSMutableData *body = [NSMutableData data];

[body appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];

[body appendData:[[NSString stringWithString:[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"userfile\"; filename=\"%@.mov\"\r\n",valuestr]] dataUsingEncoding:NSUTF8StringEncoding]];

[body appendData:[[NSString stringWithString:@"Content-Type: application/octet-stream\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];

[body appendData:[NSData dataWithData:[vedioDict valueForKey:@"VideoUrl"]]];

[body appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];

[request setHTTPBody:body];

NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];

NSXMLParser *xmlParser = [[NSXMLParser alloc] initWithData:returnData]; 

[xmlParser setDelegate:self];

[xmlParser parse];
GhostRider
Thank you ghostrider....
Gaurav aka sparsh
I had also done this same thing to upload image data to server but i am stucking when i want to choose any specific video or audio file from my iphone library.I had also tried image picker with media info for that but no result..do you have any solution for this???
Gaurav aka sparsh
can you show me your imagepicker code to pick video
GhostRider
Image_picker = [[UIImagePickerController alloc] init]; Image_picker.delegate = self; Image_picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; Image_picker.mediaTypes = [UIImagePickerController availableMediaTypesForSourceType:videoPickerCtrl.sourceType]; Image_picker.allowsImageEditing = NO; Image_picker.mediaTypes = [NSArray arrayWithObject:(NSString *)kUTTypeMovie];I am getting error on -- kUTTypeMovie
Gaurav aka sparsh
If you have any idea please tell me...
Gaurav aka sparsh
have you import file #import <MobileCoreServices/UTCoreTypes.h> and framewrok mobilecoreservices in your project
GhostRider
ok..i will try..
Gaurav aka sparsh
Hi, I am trying with new wddc code of avcamdemo but in that problem is that i am not able to save video in local cache and my phone will not support asset library.
Gaurav aka sparsh
only ios 4.0 have asset library ,you want to save video of cam in you phone ??
GhostRider
Ya, After saving i want to upload it to server...plz guide me to do that...
Gaurav aka sparsh
have you do work on audio file to save , me got problem in save audio file
GhostRider
check above post...
Gaurav aka sparsh
it is just a code to show video in imagepicker not to savevedio if you using 3g iphone then it will not work , ok i show you the code to show video of photo library
GhostRider
A: 
Hi,

By using this code you can send any audio file to server...follow this simple steps.. This steps are also applicable when you want to send image to server

NSString *postData = [NSString stringWithFormat:@"Your XML goes here";

titleForSegmentAtIndex:self.participantSegmentCtrl.selectedSegmentIndex],ratingStar,[NSString stringWithFormat:@"%d", adviceTypeSegmentCtrl.selectedSegmentIndex],USER_CREDENTIALS]; NSLog(@"local audio upload ... %@",postData); NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];

NSString *urlString = [SERVER_IP stringByAppendingString:@"getAudioadvise_ipad.php"]; NSData *audioData = [[NSData alloc]initWithContentsOfFile:fileName]; //if ([audioData length]<=0) // return;

request= [[[NSMutableURLRequest alloc] init] autorelease]; [request setURL:[NSURL URLWithString:urlString]]; [request setHTTPMethod:@"POST"];

NSString *boundary = @"---------------------------14737809831466499882746641449";

NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@",boundary];

[request addValue:contentType forHTTPHeaderField: @"Content-Type"];

NSMutableData *postbody = [NSMutableData data];

//parameter1 [postbody appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]]; [postbody appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"postData\"\r\n\r\n%@", postData] dataUsingEncoding:NSUTF8StringEncoding]]; [postbody appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]]; //Tags

[postbody appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]]; [postbody appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"userfile\"; filename=\"%@.wav\"\r\n", [schedule_Obj.ID objectAtIndex:[schedule_Obj.recordIndex intValue]]] dataUsingEncoding:NSUTF8StringEncoding]]; [postbody appendData:[[NSString stringWithString:@"Content-Type: application/octet-stream\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]]; [postbody appendData:[NSData dataWithData:audioData]];//add audio data here [postbody appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];

[request setHTTPBody:postbody]; NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil]; returnString = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding]; [audioData release];

Gaurav aka sparsh