iOS - Amazon S3 - 错误消息:当电话日期设置为某个过去日期时,“网络连接已丢失”

时间:2012-02-22 14:29:27

标签: iphone ios5 amazon-s3

我使用AWS-iOS-SDK-1.1.0将文件上传到Amazon S3。我也在使用Amazon S3 Anonymous Token Vending Machine。

当我尝试从iPhone上传文件到Amazon S3时,收到以下错误消息。

  

AmazonServiceRequest didFailWithError:
  错误域= NSURLErrorDomain代码= -1005“网络连接丢失。”
  UserInfo = 0x7290 {NSErrorFailingURLStringKey = https://.....amazonaws.com/img.jpg,NSErrorFailingURLKey = https://www.amazonaws.com/img.jpg,
  NSLocalizedDescription =网络连接丢失。,   NSUnderlyingError = 0x72a4320“网络连接丢失。”}

以下是我用来上传到S3的代码

if ([[AmazonClientManager validateCredentials] wasSuccessful]) {       
    s3PutRequest = [[S3PutObjectRequest alloc] initWithKey:[NSString stringWithFormat:@"images/%@.jpg", [user filename]] inBucket:@"bucket"];

    [s3PutRequest setCannedACL:[S3CannedACL publicRead]];        
    [s3PutRequest setFilename:[[self videoURL] path]];
    [s3PutRequest setDelegate:self];

    [[AmazonClientManager s3] putObject:s3PutRequest];
}
else {
    UIAlertView *error = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Unable to Upload the video. Please try again!!" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:nil];

    [error show];
}

#pragma mark - Amazon Service Request Delegate Methods

- (void)request:(AmazonServiceRequest *)request didReceiveResponse:(NSURLResponse *)aResponse
{
    NSLog(@"didReceiveResponse : %@", aResponse);
}

- (void)request:(AmazonServiceRequest *)request didCompleteWithResponse:(AmazonServiceResponse *)aResponse
{
    NSLog(@"didCompleteWithResponse : %@", aResponse);
    response = aResponse;

    NSLog(@"HTTP Status Code:%i", response.httpStatusCode);

    if (response.isFinishedLoading && response.httpStatusCode == 200) {
        [self saveFile];
    }
    else {
        [self uploadFailed:[exception reason]];
    }
}

- (void)request:(AmazonServiceRequest *)request didReceiveData:(NSData *)data
{
    NSLog(@"didReceiveData");
}

- (void)request:(AmazonServiceRequest *)request didSendData:(NSInteger)bytesWritten totalBytesWritten:(NSInteger)totalBytesWritten totalBytesExpectedToWrite:(NSInteger)totalBytesExpectedToWrite
{
    float percentWritten = (float)totalBytesWritten/(float)totalBytesExpectedToWrite;
    int percentageWritten = (int)(percentWritten * 100);

    [uploadProgress setProgress:percentWritten];
    [uploadPercentage setText:[NSString stringWithFormat:@"%i%%", percentageWritten]];
}

- (void)request:(AmazonServiceRequest *)request didFailWithError:(NSError *)theError
{
    NSLog(@"didFailWithError : %@", theError);
    error = theError;
    [self uploadFailed:[error localizedDescription]];
}

- (void)request:(AmazonServiceRequest *)request didFailWithServiceException:(NSException *)theException
{
    NSLog(@"didFailWithServiceException : %@", theException);
    exception = theException;

    [self uploadFailed:[exception reason]];
}

我可以通过将iPhone重置为某个过去日期来重现此错误(例如:2010年8月22日)。如果我将其重置回当前日期,我可以将文件上传到Amazon S3。

如何才能了解确切的错误消息?

2 个答案:

答案 0 :(得分:2)

根据我的经验,这是AWS SDK不足的地方。服务器端由S3完成了一些我们不知道的检查,其中之一是设备上的UTC时间必须与S3的UTC时间同步。我没有找到你得到多少缓冲空间,但我知道1天太多了。

如果检查没有通过,据我所知,S3切断了远端的连接。客户端不会收到通知,因为它假定连接丢失了。

我知道这不是你想要的反应,但它是我能提供的最好的。

来源:我遇到了时间错误并且发生这种情况的问题,以及使用多部分上传会话提交的错误eTag,终止的行为对于两者都是相同的(网络连接丢失了。)

答案 1 :(得分:2)

如前所述,Amazon SDK要求客户端和服务器的时间同步,最大允许差异为15分钟。

由于无法保证用户的设备无法保证,您可以使用此(亚马逊认可的)解决方案来解决这个问题:http://mobile.awsblog.com/post/Tx2KKPVXE69XJAO/Managing-Device-Time-with-the-AWS-Mobile-SDKs