2

I am developing an video sharing app. When I am trying to upload videos larger than 10MB NSURLConnection get lost and I got error NSURLErrorDomain Code=-1005 "The network connection was lost." . Video, less than 10 MB are uploading.Can resolution of video be an issue here?? Resolution of my video is 1280*720 .

Can anyone help me to understand issue here. This is my code for connection

NSString *urlString = [[NSString alloc]initWithString:[NSString stringWithFormat:WEBSERVICE_URL]];
urlString=[urlString stringByAddingPercentEscapesUsingEncoding:
           NSUTF8StringEncoding];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setURL:[NSURL URLWithString:urlString]];
[request setCachePolicy:NSURLRequestReloadIgnoringLocalCacheData];
[request setHTTPShouldHandleCookies:NO];
[request setTimeoutInterval:100];

[request setHTTPMethod:@"POST"];

This is not duplicate of NSURLConnection GET request returns -1005, "the network connection was lost" because I am not using third party library for connection and not using simulator. I had tried every thing from that answer.

Community
  • 1
  • 1
M Swapnil
  • 2,361
  • 3
  • 18
  • 33

1 Answers1

0

You might be hitting various timeouts—either the NSURLConnection timeout or a timeout on the server side. iOS may ignore the timeout value you specify, BTW. Or you could just be losing the network connection because your device decided to power down the cellular or Wi-Fi hardware to conserve power. Hard to say which. Or your Wi-Fi connection could have dropped because it missed too many beacons from the access point for some reason. Or....

My advice would be to upload large files a piece at a time, and then assemble the pieces on the server. That way, when (not if) the connection fails, you can re-upload the chunk that only partially transferred, and then continue uploading additional chunks until you've uploaded the whole thing.

See also the Content-Range HTTP header. Obviously, this requires your server-side code to support that functionality, but it is worth the extra effort. :-)

BTW, you forgot to set the Content-Type header.

dgatwood
  • 10,129
  • 1
  • 28
  • 49