NSURLConnection posting large video data failing in iphone 3gs
-
07-07-2021 - |
Pergunta
I am trying to upload large video file using nsurconnection in iphone 3gs.But its failing.The app crashes without any logs.The same code is working fine in iphone4. I would like to know if this is some memory limitation issue. The 3gs is uploading small videos with same code. It only fails for large size videos
here is the code i used:
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];
Solução
Have you tried streaming the HTTP body, rather than using an NSData
?
Replace
[request setHTTPBody: [NSData dataWithContentsOfURL:videoPathUrl options:0 error:&error]];
with
NSInputStream *videoStream = [[[NSInputStream alloc] initWithURL:videoPathUrl] autorelease];
[request setHTTPBodyStream:videoStream];
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow