对于CPP的使用,首先我们进行安装
# vcpkg
vcpkg install minio-cpp
# source源码
git clone https://github.com/minio/minio-cpp
cd minio-cpp
wget --quiet -O vcpkg-master.zip https://github.com/microsoft/vcpkg/archive/refs/heads/master.zip
unzip -qq vcpkg-master.zip
./vcpkg-master/bootstrap-vcpkg.sh
./vcpkg-master/vcpkg integrate 安装
cmake -B ./build -DCMAKE_BUILD_TYPE=Debug -DCMAKE_TOOLCHAIN_FILE=./vcpkg-master/scripts/buildsystems/vcpkg.cmake
cmake --build ./build --config Debug
#include <iostream>
#include <aws/core/Aws.h>
#include <aws/s3/S3Client.h>
#include <aws/s3/model/CreateBucketRequest.h>
class BucketManager {
public:
BucketManager(const std::string &endpoint, const std::string &accessKey, const std::string &secretKey) {
Aws::Client::ClientConfiguration config;
config.endpointOverride = endpoint;
config.scheme = Aws::Http::Scheme::HTTP; // Use HTTP or HTTPS based on your MinIO server configuration
client = Aws::MakeShared<Aws::S3::S3Client>("BucketManager", Aws::Auth::AWSCredentials(accessKey, secretKey), config);
}
void CreateBucket(const std::string &bucketName) {
Aws::S3::Model::CreateBucketRequest request;
request.SetBucket(bucketName);
auto outcome = client->CreateBucket(request);
if (outcome.IsSuccess()) {
std::cout << "Bucket created successfully." << std::endl;
} else {
std::cout << "Failed to create bucket: " << outcome.GetError().GetMessage() << std::endl;
}
}
private:
std::shared_ptr<Aws::S3::S3Client> client;
};
int main() {
Aws::SDKOptions options;
Aws::InitAPI(options);
{
BucketManager manager("localhost:9000", "minioadmin", "minioadmin");
manager.CreateBucket("testbucket");
}
Aws::ShutdownAPI(options);
return 0;
}