Google Cloud 存储(Google Cloud Storage)是 Google Cloud 平台提供的一种可扩展的对象存储服务,用于存储和访问大规模非结构化数据。它提供了高可用性、持久性和安全性,适用于各种应用场景,如网站托管、数据备份、多媒体存储和分析等。
Python API 是 Google Cloud 存储的一种编程接口,通过该接口可以方便地在指定位置创建存储桶(Bucket)。存储桶是 Google Cloud 存储中的基本存储单元,用于存储和组织数据对象。
以下是使用 Google Cloud 存储 Python API 在指定位置创建存储桶的示例代码:
from google.cloud import storage
def create_bucket(bucket_name, location):
"""在指定位置创建存储桶"""
storage_client = storage.Client()
bucket = storage_client.create_bucket(bucket_name, location=location)
print(f"存储桶 {bucket.name} 创建成功!")
# 调用函数创建存储桶
create_bucket("my-bucket", "us-central1")
在上述代码中,我们首先导入了 google.cloud.storage
模块,然后定义了一个 create_bucket
函数,该函数接受存储桶名称和位置作为参数。在函数内部,我们创建了一个 storage.Client
对象,并使用该对象调用 create_bucket
方法来创建存储桶。最后,我们打印出创建成功的提示信息。
领取专属 10元无门槛券
手把手带您无忧上云