在Linux上,我使用AWS CPP SDK使用以下代码从S3存储桶下载23 MB的文件。效果很好,但我也想获得下载进度。我在Google上找不到任何示例。我想我需要设置“SetDataReceivedEventHandler)回调。谁能告诉我该函数应该是什么样/如何实现并注册它?谢谢。

    GetObjectRequest getObjectRequest;
    getObjectRequest.SetBucket(bucket.c_str());
    getObjectRequest.SetKey(keyName.c_str());
    getObjectRequest.SetResponseStreamFactory([&destination](){
     return Aws::New<Aws::FStream>(
     "s3file", destination, std::ios_base::out); });

    // getObjectRequest.SetDataReceivedEventHandler() <--- How do I use this?

    GetObjectOutcome getObjectOutcome = SessionClient->GetObject(getObjectRequest);
    if(getObjectOutcome.IsSuccess())
    {
        std::cout << "<AWS DOWNLOAD> Get FW success!" << std::endl;
    }
    else
    {
        std::cout << "<AWS DOWNLOAD> Get FW failed: " << getObjectOutcome.GetError().GetMessage() << std::endl;
        exit(1);
    }

最佳答案

您是否尝试过使用TransferManager?它已经下载了progress callbacks
Full doc link

10-07 20:22