【发布时间】:2020-01-07 20:12:27
【问题描述】:
我正在尝试设置云功能以在 GCP 中的一个存储桶内的文件夹之间移动文件。
每当用户将文件加载到提供的存储桶文件夹中时,我的云函数都会将文件移动到另一个大数据脚本正在处理的文件夹中。
在设置时显示成功,但是文件没有从源文件夹中移动。
感谢您的帮助
from google.cloud import storage
def move_file(bucket_name, bucket_Folder, blob_name):
"""Moves a blob from one folder to another with the same name."""
bucket_name = 'bucketname'
blob_name = 'filename'
storage_client = storage.Client()
bucket = storage_client.get_bucket(bucket_name)
source_blob = bucket.blob("Folder1/" + blob_name)
new_blob = bucket.copy_blob(source_blob, bucket, "Folder2/" + blob_name)
blob.delete()
print('Blob {} in bucket {} copied to blob {} .'.format(source_blob.name, bucket.name, new_blob.name))
【问题讨论】:
-
你从哪里调用这个函数?请同时包含该代码。
-
标签 [batch-file] 描述是 批处理文件是包含一系列命令的文本文件,这些命令由 MS-DOS、IBM OS/2 或Microsoft Windows 系统.
-
@DustinIngram 使用上述 py 脚本创建了一个云函数。所以我从它调用这个函数。
-
您使用的是默认服务帐号还是自定义服务帐号,请查看权限详情
-
我正在使用具有适当权限的自定义服务帐户,因为我的其他云功能正常工作。我想这与调用存储桶内的文件夹中的 py 脚本有关。此外,stakedrive 日志中也没有错误。
标签: python google-cloud-platform google-cloud-functions google-cloud-storage