【发布时间】:2022-01-24 10:57:17
【问题描述】:
我是 GCP 和 GCP 存储的新手。我想将文件从 PC 上的文件系统上传到 GCS 存储桶。 我找到了以下代码并对其进行了更改。
但我有文件位于这样的文件夹中:\F1\Data\Export\PlayOnUsers\2021\12\
也就是 2021 年 12 个月 - 12 月
所以在\F1\Data\Export\PlayOnUsers\ 之后它正在改变。
我需要输入与 GCS 类似的格式。我需要创建子存储桶2021\ 和12\
这是怎么做到的? 我也没有看到您放置 GCS 凭据的部分
到目前为止我有这个代码:
from google.cloud import storage
def upload_blob(bucket_name, source_file_name, destination_blob_name):
"""Uploads a file to the bucket."""
# The ID of your GCS bucket
bucket_name = "MyBucket-scv"
# The path to your file to upload
source_file_name = "F1/Data/Export"
# The ID of your GCS object
destination_blob_name = "storage-object-name"
storage_client = storage.Client()
bucket = storage_client.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
)
)
upload_blob(.., .., ..)
# how do I pass parameters automated when calling the function?
【问题讨论】:
标签: python google-cloud-platform file-upload automation gcs