我正在使用BFTask和AWS SDK v2 iOS版上傳和下載文件到AWS S3存儲。下面的代碼工作得很好,但我想知道如果有人知道如何獲得更多的上傳允許更多的控制,並更好地接收上傳進度的反饋。我已閱讀AWS SDK v2,源代碼和BFTask自述文件的文檔,但我仍不確定如何獲得控制權。例如,如何編輯以下代碼以將BFTasks的數量同時限制爲3,並且還可以接收當前上傳的總字節數中的字節數?使用BFTask和AWS SDK控制上傳到S3的iOS v2
-(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
陣列。建議非常感謝。謝謝!
感謝您的幫助!這很好! – 2014-09-01 13:38:39