How To View And Edit Object Metadata In Cloud Storage
Hello Everyone
Welcome to CloudAffaire and this is Debjeet.
In the last blog post, we have discussed PubSub Notification in Cloud Storage.
https://cloudaffaire.com/how-to-configure-pubsub-notifications-for-cloud-storage/
In this blog post, we will discuss how to view and edit Object Metadata in Cloud Storage.
Object metadata:
Objects stored in Cloud Storage have metadata associated with them. Metadata identifies properties of the object, as well as specifies how the object should be handled when it’s accessed. Metadata exists as key:value pairs. The mutability of metadata varies: some metadata you can edit at any time, some metadata you can only set at the time the object is created, and some metadata you can only view.
Editable metadata:
There are two categories of metadata that users can change for objects:
- Fixed-key metadata: Metadata whose keys are set, but for which you can specify a value.
- Access control metadata: Cloud Storage uses Identity and Access Management (IAM) and Access Control Lists (ACLs) to control access to objects.
- Cache-Control: The Cache-Control metadata can specify two different aspects of how data is served from Cloud Storage: whether the data can be cached and whether the data can be transformed.
- Caching data: The Cache-Control metadata allows you to control whether and for how long browser and Internet caches are allowed to cache your objects, which can then be served to satisfy future requests.
- Transforming data: Cache-Control metadata also allows you to serve objects as they are stored, without applying any transformations to the data, such as removing gzip content-encoding for incompatible clients.
- Content-Disposition: The Content-Disposition metadata specifies presentation information about the data being transmitted. Setting Content-Disposition allows you to control presentation style of the content, for example determining whether an attachment should be automatically displayed or whether some form of action from the user should be required to open it.
- Content-Encoding: The Content-Encoding metadata can be used to indicate that an object is compressed, while still maintaining the object’s underlying Content-Type.
- Content-Language: The Content-Language metadata indicates the language(s) that the object is intended for.
- Content-Type: The most commonly set metadata is Content-Type (also known as media type), which allows browsers to render the object properly.
- Custom metadata: Custom metadata is metadata that you can add and remove. To create custom metadata, you specify both a value and a key. Once you have created a custom metadata key:value pair, you can delete the key or change the value.
Non-editable metadata:
Some metadata cannot be edited directly. This metadata is set at the time of object creation or rewrite. As part of the object creation or rewrite, you can set some such metadata, such as the storage class of the object or customer-managed encryption keys. Other metadata is automatically added and can only be viewed, such the generation number of the object or the time of creation.
Sample Object Metadata:
1 2 3 4 5 6 7 8 9 10 |
Creation time: Sat, 11 Jan 2020 10:50:58 GMT Update time: Sat, 11 Jan 2020 10:50:58 GMT Storage class: STANDARD Content-Length: 30 Content-Type: text/plain Hash (crc32c): ndUWPA== Hash (md5): fg92r2XBy2VcygU4i13/Og== ETag: CMfq3KOw++YCEAE= Generation: 1578739858617671 Metageneration: 1 |
How To View And Edit Object Metadata:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
###################################### ## Object Metadata In Cloud Storage ## ###################################### ## Prerequisite: gsutil/gcloud installed and configured ## https://cloudaffaire.com/gcloud-installation-and-configuration/ ## Create a bucket in cloud storage (bucket name needs to be globally unique) gsutil mb -c standard -l asia-south1 -p cloudaffaire gs://cloudaffaire_bucket_om ## Upload an object into your bucket ## Create a file for upload echo "this is my object version one" > cloudaffaire_object.txt ## Upload an object into the bucket gsutil cp cloudaffaire_object.txt gs://cloudaffaire_bucket_om ## View the metadata associated with an object: gsutil stat gs://cloudaffaire_bucket_om/cloudaffaire_object.txt ## Add a custom metadata to the object ## gsutil setmeta -h "[METADATA_KEY]:[METADATA_VALUE]" gs://[BUCKET_NAME]/[OBJECT_NAME] gsutil setmeta -h "x-goog-meta-mykey:myvalue" gs://cloudaffaire_bucket_om/cloudaffaire_object.txt ## Note custom metadata need to be prefixed with x-goog- ## Delete the object gsutil rm gs://cloudaffaire_bucket_om/cloudaffaire_object.txt ## Delete the cloud storage bucket gsutil rb gs://cloudaffaire_bucket_om |
Hope you have enjoyed this article. In the next blog post, we will discuss the Retention Policy in cloud storage.
All the public cloud providers are changing the console user interface rapidly and due to this some of the screenshots used in our previous AWS blogs are no longer relevant. Hence, we have decided that from now onwards most of the demo will be done programmatically. Let us know your feedback on this in the comment section.
To get more details on cloud storage, please refer below GCP documentation.
https://cloud.google.com/storage/docs/
https://cloud.google.com/storage/docs/metadata