问题描述
我使用 BFTask 一起的的iOS上传和下载文件到AWS S3存储。下面code工作非常好,但我想知道如果有谁知道我能获得更多的控制上传的最大数量允许,也更好的方法来接收的上传进度反馈。我已阅读为AWS SDK V2的文档,源$ C $ C,和BFTask自述但我仍然不确定我是如何获得控制权。例如,我怎么会编辑以下code,以限制BFTasks的数量同时运行3个,并获得目前上传的字节数出的总字节数?
I am using BFTask together with AWS SDK v2 for iOS to upload and download files to AWS S3 storage. The following code works very well but I am wondering if anyone know how I can gain more control over the maximum number of uploads to allow and also better approach to receiving feedback for upload progress. I have read the documentation for both AWS SDK v2, the source code, and the BFTask readme but I am still uncertain how I gain control. For example, how would I edit the following code to limit the number of BFTasks to be run simultaneously to 3 and also receive number of bytes currently uploaded out of total number of bytes?
-(void) uploadAllFileRequests
{
AWSS3TransferManager *transferManager = [AWSS3TransferManager defaultS3TransferManager];
__block int uploadCount = 0;
__block int uploadSuccess= 0;
__block int uploadFailure= 0;
NSMutableArray *tasks = [NSMutableArray new];
unsigned long totalnumberoffiles=self.arrayOfUploadRequests.count;
for (__block AWSS3TransferManagerUploadRequest *uploadRequestLocal in self.arrayOfUploadRequests)
{
[tasks addObject:[[transferManager upload:uploadRequestLocal] continueWithBlock:^id(BFTask *task) {
if (task.error != nil) {
if( task.error.code != AWSS3TransferManagerErrorCancelled
&&
task.error.code != AWSS3TransferManagerErrorPaused
)
{
NSLog(@"ERROR: %@",StatusLabelFailed);
uploadFailure ++;
}
} else {
uploadCount ++;
uploadSuccess ++;
NSLog(@"ETag: %@ %@ : %3.2f",[task.result valueForKey:@"ETag"], StatusLabelUploading, (uploadCount*1.0/totalnumberoffiles)*100.);
}
return nil;
}]];
}
[[BFTask taskForCompletionOfAllTasks:tasks] continueWithSuccessBlock:^id(BFTask *task)
{
NSLog(@"Finished: Success: %i - Failed: %i -",uploadSuccess,uploadFailure);
return nil;
}];
}
下面 self.arrayOfUploadRequests
是包含数组 AWSS3TransferManagerUploadRequest
。建议备感AP preciated。谢谢!
Here self.arrayOfUploadRequests
is an array containing AWSS3TransferManagerUploadRequest
. Suggestions are greatly appreciated. Thanks!
推荐答案
AWSRequest
, AWSS3TransferManagerUploadRequest
的父类,有称为属性上传进度
和 downloadProgress
。您可以实施 AWSNetworkingUploadProgressBlock
和 AWSNetworkingDownloadProgressBlock
检索进度的反馈。
AWSRequest
, a superclass of AWSS3TransferManagerUploadRequest
, has properties called uploadProgress
and downloadProgress
. You can implement AWSNetworkingUploadProgressBlock
and AWSNetworkingDownloadProgressBlock
to retrieve the progress feedback.
并发上传的数量限制为3的一种方法是在并行顺序执行三个任务。您可以将在序列和在此并行部分的。
One way to limit the number of concurrent uploads to three is to sequentially execute three tasks in parallel. You can combine In sequence and In parallel sections of this blog post.
这篇关于使用BFTask和AWS SDK的iOS V2控制上传到S3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!