我正在制作一个我需要上传视频和音频的应用程序,我听过很多关于mediapicker但我实际上并没有得到如何处理它。 谁能告诉我这件事。
答案 0 :(得分:0)
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];
答案 1 :(得分:0)
Hi,
通过使用此代码,您可以将任何音频文件发送到服务器...按照这个简单的步骤.. 当您想要将图像发送到服务器时,此步骤也适用
NSString *postData = [NSString stringWithFormat:@"Your XML goes here";
titleForSegmentAtIndex:self.participantSegmentCtrl.selectedSegmentIndex],ratingStar,[NSString stringWithFormat:@“%d”,adviceTypeSegmentCtrl.selectedSegmentIndex],USER_CREDENTIALS]; NSLog(@“本地音频上传...%@”,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]]; [请求setHTTPMethod:@“POST”];
NSString * boundary = @“--------------------------- 14737809831466499882746641449”;
NSString * contentType = [NSString stringWithFormat:@“multipart / form-data; boundary =%@”,boundary];
[请求addValue:contentType forHTTPHeaderField:@“Content-Type”];
NSMutableData * postbody = [NSMutableData data];
//参数1 [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 \ n%n”@,postData] dataUsingEncoding:NSUTF8StringEncoding]]; [postbody appendData:[[NSString stringWithFormat:@“\ r \ n - %@ \ r \ n”,boundary] dataUsingEncoding:NSUTF8StringEncoding]]; //标签
[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]]; //在这里添加音频数据 [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发布];