无法上传超过1分钟的视频

时间:2013-08-13 08:53:49

标签: iphone file-upload nsurlrequest

我正在处理需要视频上传功能的应用程序。我正在使用NSURLRequest,它对于长度不到1分钟的视频工作正常,但在视频很大时会导致问题。有人对此有任何想法???

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

NSString *boundary = @"----F00";
NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@",boundary];
[request addValue:contentType forHTTPHeaderField:@"Content-Type"];

fileData = [NSData dataWithContentsOfURL:[mediaDict objectForKey:UIImagePickerControllerMediaURL]];
[body appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"data[file_name]\"; filename=\"%@\"\r\n", filename] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithFormat: @"Content-Type: %@\r\n\r\n",fileContentType] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:fileData];

[request setHTTPBody:body];

NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:request delegate:self];

if (theConnection) {

    // Create the NSMutableData to hold the received data.

    // receivedData is an instance variable declared elsewhere.

    self.receivedData = [NSMutableData data];

} else {
    // Inform the user that the connection failed.
    UIAlertView *didFailWithErrorMessage = [[UIAlertView alloc] initWithTitle: @"NSURLConnection " message: @"didFailWithError"  delegate: self cancelButtonTitle: @"Ok" otherButtonTitles: nil];
    [didFailWithErrorMessage show];
    [spinnerView removeFromSuperview];
}

我真的很感谢你的帮助朋友。

1 个答案:

答案 0 :(得分:0)

设置超时间隔并检查其是否有效

NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setURL:[NSURL URLWithString:urlString]];
[request setCachePolicy:NSURLRequestUseProtocolCachePolicy];
[request setHTTPMethod:@"POST"];
[request setTimeoutInterval:6000];