How to move files in Google Cloud Storage from one bucket to another bucket by Python(如何通过 Python 将 Google Cloud Storage 中的文件从一个存储桶移动到另一个存储桶)
问题描述
是否有任何 API 函数允许我们将 Google Cloud Storage 中的文件从一个存储桶移动到另一个存储桶?
Are there any API function that allow us to move files in Google Cloud Storage from one bucket in another bucket?
场景是我们希望 Python 将 A 存储桶中的读取文件移动到 B 存储桶.我知道 gsutil 可以做到这一点,但不确定 Python 是否支持.
The scenario is we want Python to move read files in A bucket to B bucket. I knew that gsutil could do that but not sure Python can support that or not.
谢谢.
推荐答案
使用 google-api-python-client,上有一个例子storage.objects.copy 页面.复制后,您可以使用 storage.objects.delete一个>.
Using the google-api-python-client, there is an example on the storage.objects.copy page. After you copy, you can delete the source with storage.objects.delete.
destination_object_resource = {}
req = client.objects().copy(
sourceBucket=bucket1,
sourceObject=old_object,
destinationBucket=bucket2,
destinationObject=new_object,
body=destination_object_resource)
resp = req.execute()
print json.dumps(resp, indent=2)
client.objects().delete(
bucket=bucket1,
object=old_object).execute()
这篇关于如何通过 Python 将 Google Cloud Storage 中的文件从一个存储桶移动到另一个存储桶的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何通过 Python 将 Google Cloud Storage 中的文件从一个存储桶移动到另一个存储桶
基础教程推荐
- Python 中是否有任何支持将长字符串转储为块文字或折叠块的 yaml 库? 2022-01-01
- 究竟什么是“容器"?在蟒蛇?(以及所有的 python 容器类型是什么?) 2022-01-01
- matplotlib 设置 yaxis 标签大小 2022-01-01
- Kivy 使用 opencv.调整图像大小 2022-01-01
- 对多索引数据帧的列进行排序 2022-01-01
- 在 Python 中将货币解析为数字 2022-01-01
- 比较两个文本文件以找出差异并将它们输出到新的文本文件 2022-01-01
- Python,确定字符串是否应转换为 Int 或 Float 2022-01-01
- kivy 应用程序中的一个简单网页作为小部件 2022-01-01
- 在 Django Admin 中使用内联 OneToOneField 2022-01-01
