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

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

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

7条回答
  •  -上瘾入骨i
    2020-12-15 06:03

    Thank you for the Question and the chosen Best answer. Here is a code snippet that I wrote: Python Method:

    def create_folder(bucket_name, destination_folder_name):
        storage_client = storage.Client()
        bucket = storage_client.get_bucket(bucket_name)
        blob = bucket.blob(destination_folder_name)
    
        blob.upload_from_string('')
    
        print('Created {} .'.format(
            destination_folder_name))
    

    main code that calls the method:

    folder = create_folder(bucket_name, 'test-folder/')
    

提交回复
热议问题