首页 文章

将视频文件上传到URL

提问于
浏览
1

我正在尝试将视频文件上传到指定的网址 . 当我按下按钮视频文件应上传到我使用的网址 . 但没有回复 . 任何人都可以说明这一点 .

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 alloc] initWithRequest:request12 delegate:self];

if(theConnection12){webData12 = [[NSMutableData data] retain];

} else {

}

}

  • (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
[webData12 setLength:0];

} - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {

[webData12 appendData:data];

} - (void)connectionDidFinishLoading:(NSURLConnection *)connection {NSString * loginStatus12 = [[NSString alloc] initWithBytes:[webData12 mutableBytes] length:[webData12 length] encoding:NSUTF8StringEncoding];的NSLog(loginStatus12);

if(loginStatus12)
 {
  UIAlertView *statusAlert12 = [[UIAlertView alloc]initWithTitle:nil message:(NSString *)loginStatus12 delegate:self cancelButtonTitle:@"cancel" otherButtonTitles:nil];
  [statusAlert12 show];
 }
}

1 回答

  • 0

    您需要发送请求,在设置HTTPBody后添加此行

    NSData *serverReply = [NSURLConnection sendSynchronousRequest: request12 returningResponse:&response error:&error];
    

相关问题