【发布时间】: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。