Hi all. Is there a way to create sub-buckets using...
# google-cloud
s
Hi all. Is there a way to create sub-buckets using storage.Bucket()? I cannot find any examples of how it’s done. Thx!
p
That might sound stupid… is there anything like sub-buckets in GCS? I’ve never heard of it.
Unless… you meant “how to a create empty folder within GCS bucket”. If so, you can achieve that e.g. by explicitly creating an object with trailing slash in name:
Copy code
gcp.storage.BucketObject(
    "empty-folder",
    bucket=my_bucket_name,
    name='example_folder/',
    content='IT-DOES-NOT-MATTER',
)
content
field is required but it will be ignored in case object has trailing slash in name. Just a reminder, GCS (and basically most of object storage solutions) uses a flat filesystem. That means, you don’t have to actually create empty folders in order to store things within them. You can directly upload file
parent_folder/subfolder/myfile.txt
and it will “create” parent directories automatically (cause in fact, it’s just a long name with slashes and not a real tree-like structure).
🙌 1
g
I believe when you create a folder from the web console it sets a specific mime type to identify it as a folder marker. You need that if you want to
gsutil rsync
somewhere including the empty folder if I'm not mistaken
s
makes sense. Thanks a lot for the pointers