Google uses AI technology to translate content into your preferred language. AI translations can contain errors.
取得值區的儲存空間版面配置
本頁說明如何判斷值區的儲存空間配置。儲存空間配置是指物件在 bucket 中的整理方式,可以是平面命名空間或階層式命名空間。對於與 Bucket 互動的應用程式而言,版面配置非常重要,因為物件存取和操控方法會因版面配置而異。儲存空間配置也包含 bucket 位置的相關資訊。
使用 getStorageLayout API 時,應用程式可以根據值區是否使用階層式命名空間調整行為,確保最佳相容性,並根據值區設定運用適當的功能。
需要角色
如要取得 Cloud Storage bucket 儲存空間配置的必要權限,請要求管理員授予 bucket 的「Storage 物件使用者」(roles/storage.objectUser) 角色。
這個角色包含 storage.objects.list 權限,這是取得值區儲存空間配置的必要權限。
您或許還可透過其他自訂角色或預先定義的角色取得這項權限。如要瞭解哪些角色與哪些權限相關聯,請參閱「Cloud Storage 的 IAM 角色」。
如需如何授予值區角色的操作說明,請參閱「搭配值區使用 IAM」。
取得 bucket 的儲存空間版面配置
指令列
使用加上 --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},
}
後續步驟
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2026-05-29 (世界標準時間)。
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["缺少我需要的資訊","missingTheInformationINeed","thumb-down"],["過於複雜/步驟過多","tooComplicatedTooManySteps","thumb-down"],["過時","outOfDate","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["示例/程式碼問題","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2026-05-29 (世界標準時間)。"],[],[]]