adi*_*hat 4 python-3.x google-cloud-storage google-cloud-platform
我找不到使用python将本地计算机中的数据集写入google云存储的方法。我做了很多研究,但没有发现任何线索。需要帮助,谢谢
使用google-cloud Python库的简单示例:
from google.cloud import storage
def upload_blob(bucket_name, source_file_name, destination_blob_name):
"""Uploads a file to the bucket."""
storage_client = storage.Client()
bucket = storage_client.get_bucket(bucket_name)
blob = bucket.blob(destination_blob_name)
blob.upload_from_filename(source_file_name)
print('File {} uploaded to {}.'.format(
source_file_name,
destination_blob_name))
Run Code Online (Sandbox Code Playgroud)
GitHub回购中提供了更多示例:https : //github.com/GoogleCloudPlatform/python-docs-samples/blob/master/storage/cloud-client
小智 5
当我们想要将字符串写入 GCS 存储桶 blob 时,唯一需要的更改是使用blob.upload_from_string(your_string)而不是blob.upload_from_filename(source_file_name):
from google.cloud import storage
def write_to_cloud(your_string):
client = storage.Client()
bucket = client.get_bucket('bucket123456789')
blob = bucket.blob('PIM.txt')
blob.upload_from_string(your_string)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5919 次 |
| 最近记录: |