Movatterモバイル変換


[0]ホーム

URL:


Close Sidebar

C++ SDK

MinIO C++ SDK is Simple Storage Service (aka S3) client to perform bucket and object operations to any Amazon S3 compatible object storage service.

For a complete list of APIs and examples, please take a look at theMinIO C++ Client API Reference

Build requirements

  • cmake 3.10 or higher.
  • vcpkg package manager.
  • A working C++ compiler that supports at least C++17.

Installation viavcpkg

MinIO C++ client SDK can be installed viavcpkg package manager:

$ vcpkg install minio-cpp

Typicallyminio-cpp will be part of dependencies specified invcpkg.json file:

{"$schema":"https://raw.githubusercontent.com/microsoft/vcpkg-tool/main/docs/vcpkg.schema.json","name":"your-project","version":"0.0.1","dependencies":[{"name":"minio-cpp"}]}

Usingminio-cpp with cmake

MinIO C++ cliend SDK can be consumed as a dependency in CMakeLists.txt, the following can be used as an example:

cmake_minimum_required(VERSION3.10)project(miniocpp_exampleLANGUAGESCCXX)# This will try to find miniocpp package and all its dependencies.find_package(miniocppREQUIRED)# Create an executable called miniocpp-example:add_executable(miniocpp-exampleexample.cpp)# Link the executable to miniocpp and all its dependencies:target_link_libraries(miniocpp-examplePRIVATEminiocpp::miniocpp)# Make sure you are using at least C++17:target_compile_features(miniocpp-examplePUBLICcxx_std_17)

Note thatminiocpp::miniocpp is a cmake imported target, which contains all the instructions necessary to useminio-cpp library from your cmake projet file.

Hacking minio-cpp

In order to run minio-cpp tests and examples, you can do the following assumingVCPKG_ROOT points to a validvcpkg installation:

$ git clone https://github.com/minio/minio-cpp$cd minio-cpp$${VCPKG_ROOT}/vcpkg install$ cmake . -B build/Debug -DCMAKE_BUILD_TYPE=Debug -DMINIO_CPP_TEST=ON -DCMAKE_TOOLCHAIN_FILE=${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake$ cmake --build ./build/Debug

Note that cmake also supports multi-configuration generators. Multi-configuration generators don’t useCMAKE_BUILD_TYPE during configure time. For example a Visual Studio project can be setup the following way:

$ git clone https://github.com/minio/minio-cpp$cd minio-cpp$${VCPKG_ROOT}/vcpkg install$ cmake . -B build -DMINIO_CPP_TEST=ON -DCMAKE_TOOLCHAIN_FILE=${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake$ cmake --build ./build --config Debug

The examples above assumed that you havevcpkg already installed and you have aVCPKG_ROOT environment variable set. This is common if you usevcpkg to handle dependencies of multiple projects as only a single installation ofvcpkg is required in that case. If you don’t havevcpkg installed and you only want to use it to testminio-cpp, it’s possible to install it locally like this:

$ git clone https://github.com/minio/minio-cpp$cd minio-cpp$ git clone https://github.com/microsoft/vcpkg.git$ ./vcpkg/bootstrap-vcpkg.sh$ ./vcpkg/vcpkg install$ cmake . -B ./build/Debug -DCMAKE_BUILD_TYPE=Debug -DMINIO_CPP_TEST=ON -DCMAKE_TOOLCHAIN_FILE=./vcpkg/scripts/buildsystems/vcpkg.cmake$ cmake --build ./build/Debug

We recommend the setup withVCPKG_ROOT for development. In that case there is aconfigure.sh script, that can be used to create both Debug and Release projects:

$ git clone https://github.com/minio/minio-cpp$cd minio-cpp$ ./configure.sh -DMINIO_CPP_TEST=ON

Example:: file-uploader.cc

#include<miniocpp/client.h>intmain(intargc,char*argv[]){// Create S3 base URL.minio::s3::BaseUrlbase_url("play.min.io");// Create credential provider.minio::creds::StaticProviderprovider("Q3AM3UQ867SPQQA43P2F","zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG");// Create S3 client.minio::s3::Clientclient(base_url,&provider);std::stringbucket_name="asiatrip";// Check 'asiatrip' bucket exist or not.boolexist;{minio::s3::BucketExistsArgsargs;args.bucket=bucket_name;minio::s3::BucketExistsResponseresp=client.BucketExists(args);if(!resp){std::cout<<"unable to do bucket existence check; "<<resp.Error()<<std::endl;returnEXIT_FAILURE;}exist=resp.exist;}// Make 'asiatrip' bucket if not exist.if(!exist){minio::s3::MakeBucketArgsargs;args.bucket=bucket_name;minio::s3::MakeBucketResponseresp=client.MakeBucket(args);if(!resp){std::cout<<"unable to create bucket; "<<resp.Error()<<std::endl;returnEXIT_FAILURE;}}// Upload '/home/user/Photos/asiaphotos.zip' as object name// 'asiaphotos-2015.zip' to bucket 'asiatrip'.minio::s3::UploadObjectArgsargs;args.bucket=bucket_name;args.object="asiaphotos-2015.zip";args.filename="/home/user/Photos/asiaphotos.zip";minio::s3::UploadObjectResponseresp=client.UploadObject(args);if(!resp){std::cout<<"unable to upload object; "<<resp.Error()<<std::endl;returnEXIT_FAILURE;}std::cout<<"'/home/user/Photos/asiaphotos.zip' is successfully uploaded as "<<"object 'asiaphotos-2015.zip' to bucket 'asiatrip'."<<std::endl;returnEXIT_SUCCESS;}

License

This SDK is distributed under theApache License, Version 2.0, seeLICENSE for more information.

On this page

Page Feedback

Was this page helpful?

Thank you for your feedback!

How can we improve this page?

Optionally provide your email if you would like us to follow up on your feedbackPlease enter a valid email address

Sending feedback...

Failed to send feedback. Please try again.


[8]ページ先頭

©2009-2025 Movatter.jp