我最近正在开发一个 iPad (OSX 7) 应用程序,我从Amazon S3 Cloud
. 但是,这很好用,但我遇到了一些大文件的问题。如果我想下载一些视频文件,就会出现问题。
Amazon S3 Client
Connection
默认有 4 分钟的超时时间。目前我只是将超时时间增加到 20 分钟。
s3 = [[AmazonS3Client alloc] initWithCredentialsProvider:provider];
// Extended timeout because are working with larger files (default = 480 seconds)
s3.timeout = 1200; //20minutes
只需要下载一个大约 55MB 的视频文件,20 分钟后,我只下载了 42MB,所以我的应用程序卡住了。
我的问题是我只需要将超时音量增加到 2 小时,还是在下载大文件时我在做一些愚蠢的事情?!(我的意思是 10 分钟内 21MB 真的很差……)
下面是下载方法:
MYMamCloudFileRequest* req = [[MYMAMCloudManager sharedManager] generateFileRequest]; //get AmazonS3 Client
[req downloadFileWithName:mo.name withDestination:filePath andSuccessBlock:^(id result){
dispatch_async(dispatch_get_main_queue(), ^{
self.handler(MYMAMCloundImporter_RESULT_ADDED_OBJECT, status); // Handler for showing progress
});
weakSelf.currentMamObjectToBeImported++;
[weakSelf downloadNextCloudObject];
} andProgressBlock:^(NSInteger bytesDownloaded, NSInteger totalBytes){
DLOGcomment(@"Progress: %i / %i", bytesDownloaded, totalBytes); // showing current download progress
} andErrorBlock:^(MYErrorWrapper* error){
[error log];
}];
}
- (void)downloadFileWithName:(NSString*)fileName
withDestination:(NSString*)dest
andSuccessBlock:(MYMamCloudFileRequestSuccessBlock)successBlock andProgressBlock:(MYMamCloudFileRequestProgressBlock)progressBlock andErrorBlock:(MYMamCloudFileRequestErrorBlock)errorBlock {
[self getFileSize:fileName];
self.destinationFileName = dest;
self.successBlock = successBlock;
self.errorBlock = errorBlock;
self.progressBlock = progressBlock;
self.outputStream = [[NSOutputStream alloc] initToFileAtPath:dest append:NO];
[self.outputStream open];
S3GetObjectRequest *downloadRequest = [[S3GetObjectRequest alloc] initWithKey:fileName withBucket:self.bucket];
[downloadRequest setDelegate:self];
[downloadRequest setOutputStream:self.outputStream];
[self.client getObject:downloadRequest];
[requestQueue addObject:self];
}