Get a bucket's storage layout

This page describes how to determine the storage layout of your bucket. Storage layout refers to how objects are organized within a bucket, either in a flat namespace or a hierarchical namespace. The layout is important for applications that interact with the bucket, as object access and manipulation methods vary depending on the layout. Storage layout also includes information about the bucket's location.

By using the getStorageLayout API, your application can adapt its behavior based on whether a bucket uses hierarchical namespace or not, ensuring optimal compatibility and leveraging the appropriate features based on the bucket configuration.

In order to get the required permissions for getting the storage layout of a Cloud Storage bucket , ask your administrator to grant you the Storage Object User (roles/storage.objectUser) role on the bucket.

The role contains the storage.objects.list permission, which is required to get the storage layout of the bucket.

You might also be able to get this permission with other custom roles or predefined roles. To see which roles are associated with which permissions, refer to IAM roles for Cloud Storage.

For instructions on granting roles on buckets, see Use IAM with buckets.

Get a bucket's storage layout

Use the gcloud alpha storage buckets describe command with the --format flag:

gcloud alpha storage buckets describe gs://BUCKET_NAME --raw --format="default(hierarchicalNamespace)"

Where:

  • BUCKET_NAME is the name of the relevant bucket. For example, my-bucket.

If successful and hierarchical namespace is enabled, the response looks similar to the following example:

  hierarchicalNamespace:
    enabled: true
  1. Have gcloud CLI installed and initialized, which lets you generate an access token for the Authorization header.

  2. Use cURL to call the JSON API with a getStorageLayout request:

    curl -X GET \
      -H "Authorization: Bearer $(gcloud auth print-access-token)" \
      "https://storage.googleapis.com/storage/v1/b/BUCKET_NAME/storageLayout"

    Where BUCKET_NAME is the name of the relevant bucket. For example, my-bucket.

    If successful, the response looks like the following example:

      {
          "kind": "storage#storageLayout",
          "bucket": "my-bucket",
          "location": "us-central1",
          "locationType": "region",
          "hierarchicalNamespace":{enabled: true},
      }

What's next

Try it for yourself

If you're new to Google Cloud, create an account to evaluate how Cloud Storage performs in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.

Try Cloud Storage free