title: upload large video using chunks via http post
body: <p>I want to upload a large video from iPhone to a web server. I tried with below code. It's working for small files but when I try to upload large file it gets crashed.</p>
  
  <p><strong>Code:</strong></p>
  
  <pre><code>NSMutableURLRequest *request = [NSMutableURLRequest
                                  requestWithURL:[NSURL URLWithString:@"https://XXXXXXXXXXXXXXXX/submit.php"]];
  
  NSData *webData = [NSData dataWithContentsOfURL:movieUrl];
  NSString *postLength = [NSString stringWithFormat:@"%d", [webData length]];
  NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@",boundary];
  
  ---- added some HTTP headers here ----
  
  [request setHTTPMethod:@"POST"];
  [request setValue:postLength forHTTPHeaderField:@"Content-Length"];
  [request addValue:contentType forHTTPHeaderField: @"Content-Type"];
  
  NSMutableData *postbody = [NSMutableData data];
  [postbody appendData:[NSData dataWithData:webData]];
  [request setHTTPBody:postbody];
  
  NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
  </code></pre>
  
  <p>After research I got an idea as , this will be possible if I send large file in chunk of data. <a href="https://stackoverflow.com/a/15529258/1635315">solution1</a> , <a href="https://stackoverflow.com/questions/13288969/uploading-a-large-video-from-iphone-to-web-server">solution2</a>.</p>
  
  <p>I also gone through <a href="https://stackoverflow.com/a/15529258/1635315">Stream Programming apple doc.</a>
  But don't know where to define server NSURL. After writing data into output stream how to send to the server.</p>
  
  <p>If someone can point me to any working code then i will be able to understatnd it better.</p>
  
  <p>How to do that? Have any idea?</p>