Obtenir la structure de l'espace de stockage d'un bucket
Restez organisé à l'aide des collections
Enregistrez et classez les contenus selon vos préférences.
Cette page explique comment déterminer la disposition du stockage de votre bucket. La mise en page du stockage fait référence à la façon dont les objets sont organisés dans un bucket, soit dans un espace de noms plat, soit dans un espace de noms hiérarchique. La mise en page est importante pour les applications qui interagissent avec le bucket, car les méthodes d'accès et de manipulation des objets varient en fonction de la mise en page. La mise en page du stockage inclut également des informations sur l'emplacement du bucket.
En utilisant l'API getStorageLayout, votre application peut adapter son comportement selon qu'un bucket utilise ou non un espace de noms hiérarchique. Cela garantit une compatibilité optimale et permet d'exploiter les fonctionnalités appropriées en fonction de la configuration du bucket.
Rôles requis
Pour obtenir les autorisations requises pour obtenir la mise en page de stockage d'un bucket Cloud Storage , demandez à votre administrateur de vous accorder le rôle Utilisateur d'objets Storage (roles/storage.objectUser) sur le bucket.
Ce rôle contient l'autorisation storage.objects.list, qui est requise pour obtenir la mise en page du stockage du bucket.
Si vous débutez sur Google Cloud, créez un compte pour évaluer les performances de Cloud Storage en conditions réelles. Les nouveaux clients bénéficient également de 300 $ de crédits gratuits pour exécuter, tester et déployer des charges de travail.
Sauf indication contraire, le contenu de cette page est régi par une licence Creative Commons Attribution 4.0, et les échantillons de code sont régis par une licence Apache 2.0. Pour en savoir plus, consultez les Règles du site Google Developers. Java est une marque déposée d'Oracle et/ou de ses sociétés affiliées.
Dernière mise à jour le 2025/09/05 (UTC).
[[["Facile à comprendre","easyToUnderstand","thumb-up"],["J'ai pu résoudre mon problème","solvedMyProblem","thumb-up"],["Autre","otherUp","thumb-up"]],[["Difficile à comprendre","hardToUnderstand","thumb-down"],["Informations ou exemple de code incorrects","incorrectInformationOrSampleCode","thumb-down"],["Il n'y a pas l'information/les exemples dont j'ai besoin","missingTheInformationSamplesINeed","thumb-down"],["Problème de traduction","translationIssue","thumb-down"],["Autre","otherDown","thumb-down"]],["Dernière mise à jour le 2025/09/05 (UTC)."],[],[],null,["# Get a bucket's storage layout\n\n| **Preview**\n|\n|\n| This product or feature is subject to the \"Pre-GA Offerings Terms\" in the General Service Terms section\n| of the [Service Specific Terms](/terms/service-terms#1).\n|\n| Pre-GA products and features are available \"as is\" and might have limited support.\n|\n| For more information, see the\n| [launch stage descriptions](/products#product-launch-stages).\n\nThis page describes how to determine the storage layout of your bucket. Storage\nlayout refers to how objects are organized within a bucket, either in a flat\nnamespace or a [hierarchical namespace](/storage/docs/hns-overview). The layout is important for\napplications that interact with the bucket, as object access and manipulation\nmethods vary depending on the layout. Storage layout also includes information\nabout the bucket's location.\n\nBy using the [`getStorageLayout`](/storage/docs/json_api/v1/buckets/getStorageLayout) API, your application can adapt its\nbehavior based on whether a bucket uses hierarchical namespace or not, ensuring\noptimal compatibility and leveraging the appropriate features based on the\nbucket configuration.\n\n#### Roles required\n\nIn 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.\n\nThe role contains the `storage.objects.list` permission, which is\nrequired to get the storage layout of the bucket.\n\nYou might also be able to get this permission with other [custom roles](/iam/docs/creating-custom-roles) or\n[predefined roles](/iam/docs/understanding-roles#predefined). To see which roles are associated with which permissions, refer to [IAM roles for Cloud Storage.](/storage/docs/access-control/iam-roles)\n\nFor instructions on granting roles on buckets, see [Use IAM with buckets.](/storage/docs/access-control/using-iam-permissions)\n\nGet a bucket's storage layout\n-----------------------------\n\n### Command line\n\nUse the [`gcloud alpha storage buckets describe`](/sdk/gcloud/reference/alpha/storage/buckets/describe) command with the `--format` flag: \n\n```\ngcloud alpha storage buckets describe gs://BUCKET_NAME --raw --format=\"default(hierarchicalNamespace)\"\n```\n\nWhere:\n\n- \u003cvar translate=\"no\"\u003eBUCKET_NAME\u003c/var\u003e is the name of the relevant bucket. For example, `my-bucket`.\n\nIf successful and hierarchical namespace is enabled, the response looks\nsimilar to the following example: \n\n```\n hierarchicalNamespace:\n enabled: true\n```\n\n### JSON API\n\n1. Have gcloud CLI [installed and initialized](/sdk/docs/install), which lets\n you generate an access token for the `Authorization` header.\n\n\n2.\n\n Use [`cURL`](http://curl.haxx.se/) to call the [JSON API](/storage/docs/json_api)\n with a [`getStorageLayout`](/storage/docs/json_api/v1/buckets/getStorageLayout) request: \n\n ```\n curl -X GET \\\n -H \"Authorization: Bearer $(gcloud auth print-access-token)\" \\\n \"https://storage.googleapis.com/storage/v1/b/BUCKET_NAME/storageLayout\"\n ```\n\n Where \u003cvar translate=\"no\"\u003eBUCKET_NAME\u003c/var\u003e is the name of the\n relevant bucket. For example, `my-bucket`.\n\n If successful, the response looks like the following example:\n\n \u003cbr /\u003e\n\n ```json\n {\n \"kind\": \"storage#storageLayout\",\n \"bucket\": \"my-bucket\",\n \"location\": \"us-central1\",\n \"locationType\": \"region\",\n \"hierarchicalNamespace\":{enabled: true},\n }\n ```\n\n \u003cbr /\u003e\n\nWhat's next\n-----------\n\n- [Understand folders](/storage/docs/folders-overview).\n- [Create and manage folders](/storage/docs/create-folders).\n- [Rename folders](/storage/docs/rename-hns-folders).\n\nTry it for yourself\n-------------------\n\n\nIf you're new to Google Cloud, create an account to evaluate how\nCloud Storage performs in real-world\nscenarios. New customers also get $300 in free credits to run, test, and\ndeploy workloads.\n[Try Cloud Storage free](https://console.cloud.google.com/freetrial)"]]