Print the website configuration for a bucket

Stay organized with collections Save and categorize content based on your preferences.

Print the website configuration for a Cloud Storage bucket.

Code sample


For more information, see the Cloud Storage C++ API reference documentation.

namespace gcs = ::google::cloud::storage;
using ::google::cloud::StatusOr;
[](gcs::Client client, std::string const& bucket_name) {
  StatusOr<gcs::BucketMetadata> bucket_metadata =

  if (!bucket_metadata) {
    throw std::runtime_error(bucket_metadata.status().message());

  if (!bucket_metadata->has_website()) {
    std::cout << "Static website configuration is not set for bucket "
              << bucket_metadata->name() << "\n";

  std::cout << "Static website configuration set for bucket "
            << bucket_metadata->name() << "\nThe main page suffix is: "
            << bucket_metadata->website().main_page_suffix
            << "\nThe not found page is: "
            << bucket_metadata->website().not_found_page << "\n";

What's next

To search and filter code samples for other Google Cloud products, see the Google Cloud sample browser.