python - 如何选择 Google Cloud Storage 存储桶的存储类别和位置

标签 python google-cloud-storage

我可以在 Google Cloud 上创建存储桶,但无法选择存储类别 {Multi-regional、Regional、Nearline、Coldline} 或位置 {'us-west1' 等}。

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)

current documentation在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)

您可以找到适用于 Python 的 Google Cloud 客户端库的文档 here ,向您展示“Bucket”类的方法和属性。

关于python - 如何选择 Google Cloud Storage 存储桶的存储类别和位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53462523/

相关文章:

python - 我想在 azure 语音服务中添加单词级时间戳以进行连续识别

python - 同时 MySQLdb 连接看不到更新

android - 将用户数据同步到用户名/密码帐户

java - Google App Engine/Java : blobstore. 服务返回 500 服务器错误

python - 如何创建 Tkinter 主菜单

python - SQLAlchemy 与 PostgreSQL 和全文搜索

python - 使用 Python 从 Google Cloud Storage 逐行读取巨大的 JSON

c# - 谷歌云翻译.net客户端

python - 从 Octave 的符号包中避免不需要的文本

dns - 使用云存储桶静态站点将 www 重定向到非 www