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

前端 未结 7 2019
攒了一身酷
攒了一身酷 2020-12-15 05:18

How to create an empty folder on Google Storage with Google API? (Assume that / is path separator.)

7条回答
  •  有刺的猬
    2020-12-15 06:07

    @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')
    

提交回复
热议问题