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


source to share





All Articles