I have an S3 URI, and I need to extract the region, bucket and object key so that I can use the Aws::S3::Model::PutObjectRequest
to upload an object.
Does the AWS C++ SDK provide a utility function for doing purpose? Should I use a regular expression?
I note that the AWS Java SDK provides AmazonS3URI, but I haven't found anything similar so far in the C++ SDK.
Many thanks.
The AWS SDK C++ provides Aws::Crt::Io::Uri which is general but you can definitely use it with s3.
const std::string s3uri("s3://mybucket/sample-file-name");
Aws::Crt::Io::Uri uri(Aws::Crt::ByteCursor{s3uri.size(), (uint8_t*)s3uri.data()});
std::cout << "Scheme:" << Aws::Utils::StringUtils::FromByteCursor(uri.GetScheme())
<< std::endl;
std::cout << "Authority:"
<< Aws::Utils::StringUtils::FromByteCursor(uri.GetAuthority()) << std::endl;
std::cout << "Path:" << Aws::Utils::StringUtils::FromByteCursor(uri.GetPath())
<< std::endl;
Results in
Scheme:s3
Authority:mybucket
Path:/sample-file-name
Two years late but I hope someone this helps
I don't think C++ SDK supports it. But S3 URIs are just those - URIs. So any decent URI parser should be able to parse S3 URIs, your bucket name will be parsed as host
and a file key will be parsed as path
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With