NSURLConnection在iphone 3gs中发布大型视频数据失败

时间:2012-10-16 12:57:04

标签: nsurlconnection iphone-3gs

我正在尝试使用iphone 3gs中的nsurconnection上传大型视频文件。但它失败。应用程序崩溃没有任何日志。相同的代码在iphone4中工作正常。我想知道这是否是一些内存限制问题。 3gs正在使用相同的代码上传小视频。它只适用于大尺寸视频

这是我使用的代码:

NSMutableURLRequest *request=[[NSMutableURLRequest alloc]
                                              initWithURL:[NSURL URLWithString: urlString]
                                              cachePolicy:NSURLRequestUseProtocolCachePolicy
                                              timeoutInterval:6000.0];


            [request setHTTPMethod:@"POST"];
            [request setValue:postLength forHTTPHeaderField:@"Content-Length"];
            [request setValue:@"application/x-www-form-urlencoded; boundary=AaB03x" forHTTPHeaderField:@"Content-Type"];

            NSLog(@"VideoPathD:%@",videoPathUrl);
            NSError *error;
            [request setHTTPBody: [NSData dataWithContentsOfURL:videoPathUrl options:0 error:&error]];


            [NSURLConnection connectionWithRequest:request delegate:self];

1 个答案:

答案 0 :(得分:1)

您是否尝试过流式传输HTTP正文,而不是使用NSData

替换

[request setHTTPBody: [NSData dataWithContentsOfURL:videoPathUrl options:0 error:&error]];

NSInputStream *videoStream = [[[NSInputStream alloc] initWithURL:videoPathUrl] autorelease];
[request setHTTPBodyStream:videoStream];