title: Timeout POSTING to S3 from iOS using signed URLS
body: <p>My server is generating info for a signed upload to S3. When I pass that info on to iOS, it works for small files. Sometimes it works for bigger ones as well, but it often times out. I am currently testing on iOS 7 over WIFI. It's typical for it to time out after about 60% on an approximately 35 MB file, but sometimes it completes and sometimes it times out sooner.</p>
  
  <p>My server generates the following info, which I pass on as form parts to my POST. (I also tried it as parameters with similar results):</p>
  
  <ul>
  <li>AWSAccessKeyId</li>
  <li>Content-Type</li>
  <li>acl (set to private)</li>
  <li>bucket</li>
  <li>key</li>
  <li>policy</li>
  <li>signature</li>
  <li>success_action_redirect</li>
  </ul>
  
  <p>as well as a URL.</p>
  
  <p>Here is my code that generates the upload:</p>
  
  <pre><code>AFHTTPRequestOperation *op = [manager POST:url
                                  parameters:nil
                   constructingBodyWithBlock:^(id&lt;AFMultipartFormData&gt; formData)
            {
                if( throttle )
                    [formData throttleBandwidthWithPacketSize:kAFUploadStream3GSuggestedPacketSize delay:kAFUploadStream3GSuggestedDelay];
                for( id key in parameters ) {
                    NSString *val = parameters[key];                      
                    [formData appendPartWithFormData:[val dataUsingEncoding:NSUTF8StringEncoding] name:key];
                }
                NSError *error;
                if( ![formData appendPartWithFileURL:videoUrl name:@"file" fileName:@"movie.mov" mimeType:@"video/quicktime" error:&amp;error] ) {
                    // handle the error
                }
  
            } success:^(AFHTTPRequestOperation *operation, id responseObject) {
                //success
            }
                 failure:^(AFHTTPRequestOperation *operation, NSError *error) {
                     if( error.code == -1021 &amp;&amp; !throttle ) {
                         //try again with throttle:
  
                     }
                     NSLog(@"Error: %@", error);
                     // handle error
                 }];
  </code></pre>
  
  <p>This generates the following error:</p>
  
  <pre><code>Error: Error Domain=NSURLErrorDomain Code=-1001 "The request timed out." UserInfo=0x1aa15130 {NSErrorFailingURLStringKey=XXX, NSErrorFailingURLKey=XXX, NSLocalizedDescription=The request timed out., NSUnderlyingError=0x1ab94290 "The request timed out."}
  </code></pre>
  
  <p>UPDATE:</p>
  
  <p>There are several similar questions on SO I should mention. A lot of people have trouble with Heroku timeouts, but I'm uploading directly to S3.</p>
  
  <p>This person seems to have the same problem uploading to his own server:
  - <a href="https://stackoverflow.com/questions/19447921/uploading-large-files-on-ios-with-afnetworking-error-request-timeout">Uploading large files on iOS with AFNetworking - error Request Timeout</a></p>
  
  <p>This question looks like a similar problem using the AWS library, but they don't provide any code:</p>
  
  <p><a href="https://stackoverflow.com/questions/10508848/uploading-to-amazon-s3-via-afnetworking">Uploading to Amazon-S3 via AFNetworking</a></p>
  
  <p>This issue seems related, but looking at the source, it seems that length is taken into account when posting a file:</p>
  
  <p><a href="https://github.com/AFNetworking/AFNetworking/issues/1510#issuecomment-29687300" rel="nofollow noreferrer">https://github.com/AFNetworking/AFNetworking/issues/1510#issuecomment-29687300</a></p>