Reputation: 46
When we try uploading a file with metadata, there is no option to upload it along with file. Using the help of Google cloud storage doc, I found a option patch() after setting metadata to a file, but this is a kind of update to that file.
Updated metadata before calling upload_from_filename() method. But no metadata available after upload.
...
file_blob = bucket_obj.blob(gc_file_name)
file_blob.metadata = meta_data
file_blob.upload_from_filename(file_name)
...
Need some suggestions. Expected - Looking for a method which sets the metadata of a file in single step.
Upvotes: 2
Views: 1156
Reputation: 938
I've found the following information that should answer your question.
Note: Metadata-only requests are not allowed. To change an object's metadata, use either the update or patch methods.
It does not seem likely that you would be able to set it in a single step, I would recommend using update or patch as it says.
Here you have more info about update that allows you to pass metadata.
How to view and edit metadata, link.
UPDATE:
Work around for setting metadata in code, SO link.
Upvotes: 1