How to create an empty folder on Google Storage with Google API?

@SheRey - looking at folders created via the GCS web interface, the Content-Type is set to application/x-www-form-urlencoded;charset=UTF-8 but it doesn't really matter. Here's what worked for me in python:

# pip install google-cloud-storage

from google.cloud import storage

gcs_client = storage.Client(project='some_project')
bucket = gcs_client.get_bucket('some_bucket')
blob = bucket.blob('some/folder/name/')

blob.upload_from_string('', content_type='application/x-www-form-urlencoded;charset=UTF-8')

Google Cloud Storage does not have folders or subdirectories. However, there is some support for emulating them. gsutil's How Subdirectories Work is a good read for some background.

Google Cloud Storage objects are a flat namespace, but many tools, including gsutil and the Google Cloud Storage UI, create an illusion of a hierarchical file tree.

There are two widely used conventions for creating the illusion of an empty subdirectory:

  1. (recommended) Create an object that ends in a trailing slash. For example, to create a subdirectory called foo at the root of a bucket, you would create an empty object (size 0) called foo/.

  2. (legacy) Create an object with _$folder$ appended to the name. For example, to create a subdirectory called foo at the root of a bucket, you would create an empty object (size 0) called foo_$folder$.

Note that most tools and utilities are using method 1 now. Method 2 is less frequently used.