Timeout POSTING to S3 from iOS using signed URLS

风格不统一 提交于 2019-12-23 12:41:05

问题


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.

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):

  • AWSAccessKeyId
  • Content-Type
  • acl (set to private)
  • bucket
  • key
  • policy
  • signature
  • success_action_redirect

as well as a URL.

Here is my code that generates the upload:

AFHTTPRequestOperation *op = [manager POST:url
                                parameters:nil
                 constructingBodyWithBlock:^(id<AFMultipartFormData> 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:&error] ) {
                  // handle the error
              }

          } success:^(AFHTTPRequestOperation *operation, id responseObject) {
              //success
          }
               failure:^(AFHTTPRequestOperation *operation, NSError *error) {
                   if( error.code == -1021 && !throttle ) {
                       //try again with throttle:

                   }
                   NSLog(@"Error: %@", error);
                   // handle error
               }];

This generates the following error:

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."}

UPDATE:

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.

This person seems to have the same problem uploading to his own server: - Uploading large files on iOS with AFNetworking - error Request Timeout

This question looks like a similar problem using the AWS library, but they don't provide any code:

Uploading to Amazon-S3 via AFNetworking

This issue seems related, but looking at the source, it seems that length is taken into account when posting a file:

https://github.com/AFNetworking/AFNetworking/issues/1510#issuecomment-29687300


回答1:


For those who end up on this page. The pressigned URL probably had an "expires" value that is too short for the upload. I touch on this at Taming the AWS framework to upload a large file to S3 for iOS. Look for "CREATE THE PARTS' UPLOAD REQUESTS", it covers setting that value. I managed to upload 500Mb file this way.




回答2:


It happens to me on video files as well, mp4 files. The thing is that my video files are small (2-5MB max).

I'm using AWSiOSSD 2.5.2, iPhones 6s 7 and 7plus with versions 10+ (including the latest ver).

No workarounds worked so far, including otusweb answer posted 6 months ago on this thread.



来源:https://stackoverflow.com/questions/20551548/timeout-posting-to-s3-from-ios-using-signed-urls

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!