gpt4 book ai didi

google-app-engine - 以编程方式在 python 中的 App Engine 云存储上模拟 "gsutil mv"

转载 作者:太空宇宙 更新时间:2023-11-03 15:25:18 25 4
gpt4 key购买 nike

我想在谷歌云存储上实现一个 mv(云中复制)操作,类似于 gsutil 的操作方式 ( http://developers.google.com/storage/docs/gsutil/commands/mv )。

我之前在某处读到这涉及到数据的读写(下载和重新上传),但我找不到这些段落了。

这是在云存储中移动文件的正确方法,还是必须向下一层到 boto 库以避免通过网络复制数据以重命名文件?

istream = cloudstorage.open(src, mode='r')
ostream = cloudstorage.open(dst, content_type=src_content, mode='w')

while True:
buf = istream.read(500000)
if not buf:
break

ostream.write(buf)

istream.close()
ostream.close()

更新:我找到了支持复制和组合操作等的 rest api。似乎我们有希望不必跨大陆复制数据来重命名某些东西。

我目前找到的有用链接 ...

最佳答案

使用JSON API,有一个copy method .这是 Python 的官方示例,使用 Python Google Api Client lib :

# The destination object resource is entirely optional. If empty, we use
# the source object's metadata.
if reuse_metadata:
destination_object_resource = {}
else:
destination_object_resource = {
'contentLanguage': 'en',
'metadata': {'my-key': 'my-value'},
}
req = client.objects().copy(
sourceBucket=bucket_name,
sourceObject=old_object,
destinationBucket=bucket_name,
destinationObject=new_object,
body=destination_object_resource)
resp = req.execute()
print json.dumps(resp, indent=2)

关于google-app-engine - 以编程方式在 python 中的 App Engine 云存储上模拟 "gsutil mv",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18697418/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com