Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix example code in README #88

Merged
merged 1 commit into from
Aug 21, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 10 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,56 +32,54 @@ $ cmake --build ./build --config Debug

int main(int argc, char* argv[]) {
// Create S3 base URL.
minio::http::BaseUrl base_url;
base_url.SetHost("play.min.io");
minio::s3::BaseUrl base_url("play.min.io");

// Create credential provider.
minio::creds::StaticProvider provider(
"Q3AM3UQ867SPQQA43P2F", "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG");

// Create S3 client.
minio::s3::Client client(base_url, &provider);

std::string bucket_name = "asiatrip";

// Check 'asiatrip' bucket exist or not.
bool exist;
{
minio::s3::BucketExistsArgs args;
args.bucket_ = bucket_name;
args.bucket = bucket_name;

minio::s3::BucketExistsResponse resp = client.BucketExists(args);
if (!resp) {
std::cout << "unable to do bucket existence check; " << resp.GetError()
std::cout << "unable to do bucket existence check; " << resp.Error()
<< std::endl;
return EXIT_FAILURE;
}

exist = resp.exist_;
exist = resp.exist;
}

// Make 'asiatrip' bucket if not exist.
if (!exist) {
minio::s3::MakeBucketArgs args;
args.bucket_ = bucket_name;
args.bucket = bucket_name;

minio::s3::MakeBucketResponse resp = client.MakeBucket(args);
if (!resp) {
std::cout << "unable to create bucket; " << resp.GetError() << std::endl;
std::cout << "unable to create bucket; " << resp.Error() << std::endl;
return EXIT_FAILURE;
}
}

// Upload '/home/user/Photos/asiaphotos.zip' as object name
// 'asiaphotos-2015.zip' to bucket 'asiatrip'.
minio::s3::UploadObjectArgs args;
args.bucket_ = bucket_name;
args.object_ = "asiaphotos-2015.zip";
args.filename_ = "/home/user/Photos/asiaphotos.zip";
args.bucket = bucket_name;
args.object = "asiaphotos-2015.zip";
args.filename = "/home/user/Photos/asiaphotos.zip";

minio::s3::UploadObjectResponse resp = client.UploadObject(args);
if (!resp) {
std::cout << "unable to upload object; " << resp.GetError() << std::endl;
std::cout << "unable to upload object; " << resp.Error() << std::endl;
return EXIT_FAILURE;
}

Expand Down