How to upload directory using transfer manager. #3399
Answered
by
sbiscigl
sulaimansuhas
asked this question in
Q&A
|
Hey, I have been trying to upload directories using transfer manager as I see it is an available function. My code looks somewhat like this: When this code is run nothing happens: the call backs don't get called, nothing particular is showing up in the logs. Any help here would be appreciated! |
Answered by
sbiscigl
Apr 29, 2025
Replies: 1 comment
|
Hey thanks for reaching out, we typically ask for minimal reproducible example when looking into a issue. I created a short test applicaiton for you that should work for you. CMakeLists.txt: cmake_minimum_required(VERSION 3.13)
project(sdk_usage_workspace)
set(CMAKE_CXX_STANDARD 20)
find_package(AWSSDK REQUIRED COMPONENTS transfer s3)
add_executable(${PROJECT_NAME} "main.cpp")
target_link_libraries(${PROJECT_NAME} PRIVATE ${AWSSDK_LINK_LIBRARIES})
main.cpp: #include <aws/core/Aws.h>
#include <aws/core/utils/threading/PooledThreadExecutor.h>
#include <aws/s3/S3Client.h>
#include <aws/transfer/TransferManager.h>
using namespace Aws;
using namespace Aws::S3;
using namespace Aws::Transfer;
using namespace Aws::Utils;
using namespace Aws::Utils::Threading;
namespace {
const char* LOG_TAG = "test-app";
}
auto main(int argc, char *argv[]) -> int {
if (argc != 4) {
std::cout << "Usage: " << argv[0] << "local-directory bucket-name prefix" << std::endl;
return EXIT_FAILURE;
}
const char* directory = argv[1];
const char* bucketName = argv[2];
const char* prefix = argv[3];
SDKOptions options{};
options.loggingOptions.logLevel = Logging::LogLevel::Debug;
InitAPI(options);
{
PooledThreadExecutor pooled_thread_executor{1};
auto client = Aws::MakeShared<S3Client>(LOG_TAG);
TransferManagerConfiguration configuration{&pooled_thread_executor};
configuration.s3Client = std::move(client);
configuration.transferInitiatedCallback = [](const TransferManager*,
const std::shared_ptr<const TransferHandle> &handle) -> void
{
std::cout << "Started upload for: " << handle->GetKey() << "\n";
};
configuration.transferStatusUpdatedCallback = [](const TransferManager*,
const std::shared_ptr<const TransferHandle> &handle) -> void
{
if (handle->GetStatus() == TransferStatus::COMPLETED) {
std::cout << "Upload completed for: " << handle->GetKey() << "\n";
} else if (handle->GetStatus() == TransferStatus::IN_PROGRESS) {
std::cout << "Upload in progress: " << handle->GetKey() << "\n";
} else if (handle->GetStatus() == TransferStatus::FAILED) {
std::cout << "Upload failed: " << handle->GetKey() << "\n";
}
};
configuration.errorCallback = [](const TransferManager*,
const std::shared_ptr<const TransferHandle> &handle,
const Client::AWSError<S3Errors> &error) -> void
{
std::cout << "Error: " << handle->GetKey() << ", "
<< error.GetExceptionName() << ", "
<< error.GetMessage()<< "\n";
};
const auto manager = TransferManager::Create(configuration);
manager->UploadDirectory(directory, bucketName, prefix, {});
manager->WaitUntilAllFinished();
}
ShutdownAPI(options);
return 0;
}if you run it using something like you should see logs like |
0 replies
Answer selected by
jmklix
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey thanks for reaching out, we typically ask for minimal reproducible example when looking into a issue. I created a short test applicaiton for you that should work for you.
CMakeLists.txt:
main.cpp: