C++ S3 GetObject minimal streaming example using minio-cpp
#include <client.h>
#include <iostream>
using std::cout, std::endl;
int main(int argc, char* argv[]) {
// Create S3 base URL.
minio::s3::BaseUrl base_url("minio.mydomain.com");
// Create credential provider.
minio::creds::StaticProvider provider(
"my-access-key", "my-secret-key");
// Create S3 client.
minio::s3::Client client(base_url, &provider);
std::string bucket_name = "my-bucket";
// Build arguments object
minio::s3::GetObjectArgs args;
args.bucket = bucket_name;
args.object = "my-object.txt";
args.datafunc = [](minio::http::DataFunctionArgs args) -> bool {
// This function will be called for every data chunk of the object
cout << args.datachunk;
return true;
};
// Perform the request (calling datafunc for every chunk)
minio::s3::GetObjectResponse resp = client.GetObject(args);
// Handle error (if any)
if (resp) {
cout << endl // end line after file content
<< "data of my-object is received successfully" << endl;
} else {
cout << "Error during GetObject(): " << resp.Error().String() << endl;
}
return EXIT_SUCCESS;
}