Skip to content Skip to sidebar Skip to footer

Set Metadata In Google Cloud Storage Using Gcloud-python

I am trying to upload a file to Google Cloud Storage using gcloud-python and set some custom metadata properties. To try this I have created a simple script. import os from gcloud

Solution 1:

We discussed on the issue tracker and it surfaced a "bug" in the implementation, or at the very least something which catches users off guard.

Accessing metadata via blob.metadata is read-only. Thus when mutating that result via

blob.metadata['Color'] = 'Pink'

it doesn't actually change the metadata stored on blob.

The current "fix" is to just build up

metadata = {'Color': 'Pink'}
blob.metadata = metadata

Solution 2:

blob.content_disposition = "attachment"
blob.patch()

Post a Comment for "Set Metadata In Google Cloud Storage Using Gcloud-python"