如何检查使用Aws :: Transfer :: Transfermanager的下载是否成功?

时间:2019-01-18 13:46:27

标签: c++ amazon-s3 aws-sdk

我从AWS S3下载了一个文件,在方法结束时,我想返回它的成功,但可惜我不知道该怎么做。

我尝试使用所获得的TransferHandle来执行此操作,但似乎对此没有选择。

bool downloadObject(const std::shared_ptr<Aws::S3::S3Client> & client, const Aws::String &key_name)
{
const auto executor = Aws::MakeShared<Aws::Utils::Threading::PooledThreadExecutor>("Downloading-File", 4);
auto transferInitCallback = [&](const Aws::Transfer::TransferManager*, const std::shared_ptr<const Aws::Transfer::TransferHandle>& handle) {};

Aws::Transfer::TransferManagerConfiguration transferConfig(executor.get());
transferConfig.s3Client = client;
transferConfig.transferInitiatedCallback = transferInitCallback;

const auto transmanager = Aws::Transfer::TransferManager::Create(transferConfig);
const auto handle = transmanager->DownloadFile("bucketName", key_name, "C:/Development/test.gz");

handle->WaitUntilFinished();    // block calling thread until download complete

//if download == success -> return true;
}

1 个答案:

答案 0 :(得分:1)

您可以使用GetStatus来检查是否成功,例如:

return handle->GetStatus() == Aws::Transfer::TransferStatus::COMPLETED