本页面介绍如何确定存储桶的存储布局。存储布局是指对象在存储桶内的整理方式,即采用扁平命名空间或分层命名空间。布局对于与存储桶交互的应用非常重要,因为对象访问和操纵方法因布局而异。存储空间布局还包含有关存储桶位置的信息。
通过使用 getStorageLayout
API,您的应用可以根据存储桶是否使用分层命名空间来调整其行为,从而确保最佳兼容性并根据存储桶配置利用相应功能。
获取存储桶的存储布局
命令行
使用带有 --format
标志的 gcloud alpha storage buckets describe
命令:
gcloud alpha storage buckets describe gs://BUCKET_NAME --raw --format="default(hierarchicalNamespace)"
其中:
BUCKET_NAME
是相关存储分区的名称,例如my-bucket
。
如果成功并且已启用分层命名空间,则响应类似于以下示例:
hierarchicalNamespace: enabled: true
JSON API
安装并初始化 gcloud CLI,以便为
Authorization
标头生成访问令牌。使用
cURL
,通过getStorageLayout
请求调用 JSON API:curl -X GET \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ "https://storage.s3nsapis.fr/storage/v1/b/BUCKET_NAME/storageLayout"
其中
BUCKET_NAME
是相关存储桶的名称。例如my-bucket
。如果成功,则响应类似如下示例:
{ "kind": "storage#storageLayout", "bucket": "my-bucket", "location": "us-central1", "locationType": "region", "hierarchicalNamespace":{enabled: true}, }