Iphone iOS-AmazonS3-错误消息:“;“网络连接已断开”;当电话日期设置为某个过去日期时
我正在使用AWS-iOS-SDK-1.1.0将文件上载到AmazonS3。我也在使用亚马逊S3匿名令牌自动售货机 当我试图从iPhone向Amazon S3上传文件时,收到以下错误消息 AmazonServiceRequest失败:错误:Iphone iOS-AmazonS3-错误消息:“;“网络连接已断开”;当电话日期设置为某个过去日期时,iphone,ios5,amazon-s3,Iphone,Ios5,Amazon S3,我正在使用AWS-iOS-SDK-1.1.0将文件上载到AmazonS3。我也在使用亚马逊S3匿名令牌自动售货机 当我试图从iPhone向Amazon S3上传文件时,收到以下错误消息 AmazonServiceRequest失败:错误: Error Domain=NSURLErrorDomain Code=-1005“网络连接丢失。” UserInfo=0x7290{NSErrorFailingURLStringKey=https://.....amazonaws.com/img.jpg,n错
Error Domain=NSURLErrorDomain Code=-1005“网络连接丢失。”
UserInfo=0x7290{NSErrorFailingURLStringKey=https://.....amazonaws.com/img.jpg,n错误失败键=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日)来重现此错误。如果我将其重置回当前日期,我就能够将该文件上载到AmazonS3
如何才能知道确切的错误消息?以我的经验,这就是AWS SDK的不足之处。我们不知道S3在服务器端完成了一些检查,其中之一是设备上的UTC时间必须与S3的UTC时间同步。我还没有发现你们有多少缓冲空间,但我知道一天太多了 如果检查不通过,据我所知,S3会切断远程端的连接。客户端没有收到通知,因此它假定连接只是丢失了 我知道这不是你想要的答复,但这是我能提供的最好的答复
来源:我遇到了一些问题,由于时间不对,并且发生了这种情况,以及在多部分上传会话中提交了不正确的ETag,终止行为对两者都是一样的(网络连接丢失)。如前所述,AmazonSDK要求客户端和服务器的时间同步,最大允许时间差为15分钟
由于在用户的设备上无法保证这一点,因此您可以使用此(亚马逊认可的)解决方案来解决这一问题:您需要提供一些代码,向我们准确显示如何将文件上载到S3。