【问题标题】:iOS - Amazon S3 - Error Message: "The network connection was lost" when phone date set to some past dateiOS - Amazon S3 - 错误消息:当电话日期设置为某个过去的日期时“网络连接丢失”
【发布时间】:2012-02-22 14:29:26
【问题描述】:

我正在使用 AWS-iOS-SDK-1.1.0 将文件上传到 Amazon S3。我也在使用 Amazon S3 匿名令牌自动售货机。

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

AmazonServiceRequest didFailWithError :
错误域=NSURLErrorDomain 代码=-1005 “网络连接丢失。”
UserInfo=0x7290 {NSErrorFailingURLStringKey=https://.....amazonaws.com/img.jpg, NSErrorFailingURLKey=https://.....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。

我怎样才能知道确切的错误信息?

【问题讨论】:

  • 您需要提供一些代码,向我们展示您如何将文件上传到 S3。

标签: iphone ios5 amazon-s3


【解决方案1】:

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

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

【讨论】:

    【解决方案2】:

    根据我的经验,这就是 AWS 开发工具包的不足之处。 S3 在服务器端进行了一些我们不知道的检查,其中之一是设备上的 UTC 时间必须与 S3 的 UTC 时间同步。我没有找到你有多少缓冲空间,但我知道 1 天太多了。

    如果检查没有通过,据我所知,S3 会切断来自远程端的连接。没有通知客户端原因,因此它假定连接只是丢失了。

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

    来源:我遇到了时间错误并发生这种情况的问题,以及通过分段上传会话提交的 eTag 不正确,两者的终止行为相同(网络连接丢失。)

    【讨论】:

      猜你喜欢
      • 2015-03-22
      • 2023-03-20
      • 1970-01-01
      • 2013-03-09
      • 2020-05-08
      • 2015-09-18
      • 2017-05-05
      • 1970-01-01
      • 2012-09-27
      相关资源
      最近更新 更多