我正在尝试使用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];
答案 0 :(得分:1)
您是否尝试过流式传输HTTP正文,而不是使用NSData
?
替换
[request setHTTPBody: [NSData dataWithContentsOfURL:videoPathUrl options:0 error:&error]];
与
NSInputStream *videoStream = [[[NSInputStream alloc] initWithURL:videoPathUrl] autorelease];
[request setHTTPBodyStream:videoStream];