title: Upload big video from PhotoLibrary to server
body: <p>I have a problem with uploading big video asset to a server from PhotoLibrary.</p>
  
  <p>I get my asset data as <a href="https://stackoverflow.com/questions/4545982/getting-video-from-alasset?answertab=active#tab-top">described here</a>, export the video to local document, and then upload.</p>
  
  <p>But when I upload a big video (2 minutes and about 300Mb or more in size), this method causes a crash and I got no reason nor any any information.</p>
  
  <p>I use <code>webDAV</code> to upload files just like this:</p>
  
  <pre><code>    // Set up credentials
      NSURLCredential *userCredentials = [NSURLCredential credentialWithUser:username
                                                                    password:password
                                    persistence:NSURLCredentialPersistenceForSession];
      NSURLProtectionSpace *space = [[NSURLProtectionSpace alloc] initWithHost:host
                                                                          port:80
                                                                      protocol:@"http"
                                                                         realm:@" webDAV"
                                                          authenticationMethod:nil];
      [[NSURLCredentialStorage sharedCredentialStorage] setCredential:userCredentials forProtectionSpace:space];
      [space release];
  
      // Create the request
      NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:url];
      [request setHTTPMethod:@"PUT"];
      [request setValue:[self mimetypeForFile:self.filepath] forHTTPHeaderField:@"Content-Type"];
      NSNumber *contentLength = (NSNumber *) [[[NSFileManager defaultManager]
                                               attributesOfItemAtPath:self.filepath error:NULL]
                                              objectForKey:NSFileSize];
      [request setValue:[contentLength description] forHTTPHeaderField:@"Content-Length"];
  
      if (self.useStreaming)
      {
          if (self.currentFileStream!=nil)
          {
              [self.currentFileStream close], self.currentFileStream = nil;
          }
          self.currentFileStream = [NSInputStream inputStreamWithFileAtPath:self.filepath];
  
          if (currentFileStream!=nil)
          {
              [request setHTTPBodyStream:currentFileStream];
          }
          else
          {
              [request setHTTPBody:[NSData dataWithContentsOfFile:self.filepath]];
          }
      }
      else
      {
          [request setHTTPBody:[NSData dataWithContentsOfFile:self.filepath]];
      }
  
  
  
      NSURLConnection* conn = [[NSURLConnection alloc] initWithRequest:request delegate:self];
  
      if (self.currentConnection!=nil)
      {
          self.currentConnection = nil;
      }
      self.currentConnection = conn;
      [conn release];
      [self.currentConnection start];
  </code></pre>
  
  <p>When the code reache this line:</p>
  
  <p><code>self.currentFileStream = [NSInputStream inputStreamWithFileAtPath:self.filepath];
              [request setHTTPBodyStream:currentFileStream];</code></p>
  
  <p>OR:</p>
  
  <pre><code>[request setHTTPBody:[NSData dataWithContentsOfFile:self.filepath]];
  </code></pre>
  
  <p>It crashed.</p>
  
  <p>Do you have any suggestion?</p>
  
  <p>Thanks.</p>
  
  <p>========================</p>
  
  <p><strong>Edit: It crash at <code>setHTTPBody:</code> OR  <code>setHTTPBodyStream:</code></strong>
   So I think it's about memory leak or something.</p>
  
  <p>================</p>
  
  <p><strong>EDIT2:</strong> Now I decide to compress video, I get video data by current method is too large(more than 300mb)， But I find use <code>UIImagePickerController</code> select the same video, it just 30mb； So compress is help; <strong>I'll try <code>UIVideoEditorController</code>, and will post my result soon;</strong></p>