上传视频文件到URL
问题描述:
我想上传视频文件到指定的网址。当我按下按钮视频文件应该上传到我使用的网址。但没有反应。任何人都可以给出理由。上传视频文件到URL
enter code here
NSString *filePath = [[NSBundle mainBundle]pathForResource:@"3idiots" ofType:@"mov"];
NSURL *uploadurl=[NSURL URLWithString:@"http://115.111.27.206:8081/vblo/upload.jsp"];
//NSData *postVideoData = [NSData dataWithContentsOfFile:filePath];
NSData *postVideoData = [string dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *postVideoLength = [NSString stringWithFormat:@"%d", [postVideoData length]];
NSMutableURLRequest *request12 = [[[NSMutableURLRequest alloc] init] autorelease];
[request12 setURL:uploadurl];
[request12 setHTTPMethod:@"POST"];
[request12 setValue:postVideoLength forHTTPHeaderField:@"Content-Length"];
[request12 setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request12 setHTTPBody:postVideoData];
NSURLConnection的* theConnection12 = [[NSURLConnection的页头] initWithRequest:request12委托:自我];
if(theConnection12) webData12 = [[NSMutableData data] retain];
} 别的 {
}
}
- (无效)连接:(NSURLConnection的*)连接didReceiveResponse:(NSURLResponse *)响应 {
[webData12 setLength:0];
- (void)连接:(NSURLConnection *)连接didReceiveData:(N SDATA *)数据 {
[webData12 appendData:data];
} - (无效)connectionDidFinishLoading:(NSURLConnection的*)连接 { 的NSString * loginStatus12 = [[的NSString的alloc] initWithBytes:[webData12 mutableBytes]长度:[webData12长度]编码:NSUTF8StringEncoding]; NSLog(loginStatus12);
if(loginStatus12)
{
UIAlertView *statusAlert12 = [[UIAlertView alloc]initWithTitle:nil message:(NSString *)loginStatus12 delegate:self cancelButtonTitle:@"cancel" otherButtonTitles:nil];
[statusAlert12 show];
}
}
答
你需要发送请求,您将HTTPBody
NSData *serverReply = [NSURLConnection sendSynchronousRequest: request12 returningResponse:&response error:&error];
你真的需要清理这个代码后添加此行,这是很难读......还什么是在变量“字符串”看起来像你已经注释掉了实际的视频数据 – 2010-11-19 13:48:20