我正在使用AWSS3将我的媒体上传到亚马逊。 这就是我在做的事情:
Bool uploaded = NO;
dispatch_async("my.queue.whatever", ^{
NSData *mediaData = UIImagePNGRepresentation(mediaImage);//mediaImage of type uiimage
NSString *pictureName = @"randomstring";
AmazonCredentials *amazonCredentials = [[AmazonCredentials alloc] initWithAccessKey:@"myAccessKey" withSecretKey:@"mySecretKey" withSecurityToken:@"mySessionToken"];
AmazonS3Client *s3Client = [[AmazonS3Client alloc] initWithCredentials:amazonCredentials];
S3PutObjectRequest *s3Request = [[S3PutObjectRequest alloc] initWithKey:pictureName inBucket:@"myPictureBucket"];
s3Request.delegate = self;
//s3Request.contentType = CONTENT_TYPE;
s3Request.cannedACL = [S3CannedACL publicRead];
s3Request.data = mediaData;
[s3Client putObject:s3Request];
do {
[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]];
} while (!uploaded);
);
这些是我的代表职能:
-(void)request:(AmazonServiceRequest *)request didCompleteWithResponse:(AmazonServiceResponse *)response
{
uploaded = YES;
}
-(void)request:(AmazonServiceRequest *)request didFailWithError:(NSError *)error{
uploaded = YES;
}
- (void)request:(AmazonServiceRequest *)request didFailWithServiceException:(NSException *)exception{
NSLog(@"didFailWithServiceException %@",[exception description]);
uploaded = YES;
}
- (void)request:(AmazonServiceRequest *)request didSendData:(long long)bytesWritten totalBytesWritten:(long long)totalBytesWritten totalBytesExpectedToWrite:(long long)totalBytesExpectedToWrite{}
-(void)request:(AmazonServiceRequest *)request didReceiveResponse:(NSURLResponse *)response{}
-(void)request:(AmazonServiceRequest *)request didReceiveData:(NSData *)data{}
当函数didFailWithServiceException被调用时,它给出了错误:“Request timed out”。我在谷歌找不到任何东西。需要你的帮助!!感谢
答案 0 :(得分:0)
尝试增加默认超时:
s3Client.timeout = desiredtimeout;
我正在尝试上传操作的一些问题,它开始上传,但几秒后代理不再被调用。
request: didSendData: totalBytesWritten: totalBytesExpectedToWrite:
我不知道框架或亚马逊服务器中是否存在某些错误,或者只是我的代码中存在一些错误。