AFHTTPRequest for S3 public file not working for some users

I have a bucket of files accessible through my application. The application downloads a package of these files using AFHTTPRequestOperation

via AFHTTPRequestOperationManager

. For almost all users, this works seamlessly. For a very small number of users, all downloads fail with various error messages.

Most of the error messages Request failed: not found (404)

, and about 5-10% are The operation couldn’t be completed. (NSURLErrorDomain error -999.)

, The operation couldn’t be completed. No such file or directory

and The network connection was lost

.

Users who experience crashes get the same crash every time they redownload files until they uninstall the app and reinstall it. Other users with the same application download files without issue.

Here is the code used to download the files:

-(void)beginDownloadsHTTP {
  NSString *baseURL = @"https://s3.amazonaws.com/";
  _afHTTPManager = [[AFHTTPRequestOperationManager alloc] initWithBaseURL:[NSURL URLWithString:baseURL]];

  for (int i = 0; i < 5; i++) {
    [self downloadOneFileHTTP:_fileKeys.anyObject];
  }
}

-(void)downloadOneFileHTTP:(NSString *)oneKey {
  [_fileKeys removeObject:oneKey];
  NSString *baseURL = @"https://s3.amazonaws.com/";
  NSString *plusKey = [oneKey stringByReplacingOccurrencesOfString:@" " withString:@"+"];
  NSString *downloadURL = [NSString stringWithFormat:@"%@%@/%@", baseURL, _bucketName, plusKey];

  NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:downloadURL]];
  NSString *downloadPath = [self downloadPathForItem:oneKey];      

  AFHTTPRequestOperation *op = [_afHTTPManager HTTPRequestOperationWithRequest:request success:^(AFHTTPRequestOperation *operation, id responseObject) {

    if (_fileKeys.count > 0) {
      [self downloadOneFileHTTP:_fileKeys.anyObject]; 
    }

  } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
    [self fileDidFailWithKey:oneKey andError:error];

  }];
  op.securityPolicy.allowInvalidCertificates = YES;
  op.outputStream = [NSOutputStream outputStreamToFileAtPath:downloadPath append:NO];
  [_afHTTPManager.operationQueue addOperation:op];
}

      

Any ideas where the problem is coming from? There seems to be some setting stored in the phone that always causes a certain set of files to crash and uninstalling the app clears that setting, but I don't know where to look for it.

+3
amazon-s3 afnetworking


source to share


No one has answered this question yet

Check out similar questions:

208
Create a bucket in Amazon S3
190
Request error: Inappropriate content type: text / html using AFNetworking 2.0
72
How to make 10,000 files in S3 public
4
AFNetworking does not resume download
3
Afnetworking 2.0 PUT image
2
AFNetworking with unreliable wifi - Detect / Retry connection on timeout
1
iOS AWS v2 S3 Transfer Manager must use specified endpoint
1
AFNetworking and NSURLRequest hang / beachball timeout
0
How do I check the receipt of an in-app purchase?
-4
AFNetworking Always Fails



All Articles
Loading...
X
Show
Funny
Dev
Pics