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 import storage
client = storage.Client('super secret app id')
bucket = client.get_bucket('super secret bucket name')
blob = bucket.get_blob('kirby.png')
blob.metadata = blob.metadata or {}
blob.metadata['Color'] = 'Pink'
with open(os.path.expanduser('~/Pictures/kirby.png'), 'rb') as img_data:
blob.upload_from_file(img_data)
I am able to upload the file contents. After uploading the file I am able to manually set metadata from the developer console and retrieve it.
I can't figure out how to upload the metadata programmatically.