Python 如何为Google云存储桶选择存储类别和位置
我可以在谷歌云上创建存储桶,但我不能选择存储类{Multi-regional、regional、Nearline、Coldline}或位置{'us-west1',等等}Python 如何为Google云存储桶选择存储类别和位置,python,google-cloud-storage,Python,Google Cloud Storage,我可以在谷歌云上创建存储桶,但我不能选择存储类{Multi-regional、regional、Nearline、Coldline}或位置{'us-west1',等等} from google.cloud import storage def CreateBucket(name): try: storageClient = storage.Client() bucket = storageClient.create_bucket(name)
from google.cloud import storage
def CreateBucket(name):
try:
storageClient = storage.Client()
bucket = storageClient.create_bucket(name)
print(f'Bucket {bucket.name} created.')
except Exception as ex:
print(f'exception!\n{ex}')
name = 'my_globally_unique_bucket_name'
CreateBucket(name)
在Python中,不显示bucket_name之外的任何参数;但是,Go、Java、Node.JS和Ruby都会显示存储类和位置选项的参数。将代码更改为:
from google.cloud import storage
def CreateBucket(name):
try:
storageClient = storage.Client()
bucket = storageClient.bucket(name)
bucket.location = "us-west1"
bucket.storage_class = "COLDLINE"
bucket.create()
print("Bucket {} created.".format(name))
except Exception as ex:
print("exception!\n{}".format(ex))
name = 'my_globally_unique_bucket_name'
CreateBucket(name)
您可以找到Google Cloud Client Library for Python的文档,其中显示了类“Bucket”的方法和属性