Programmatically emulating “gsutil mv” on appengine cloudstorage in python

前端 未结 1 804
醉酒成梦
醉酒成梦 2021-02-10 11:08

I would like to implement a mv (copy-in-the-cloud) operation on google cloud storage that is similar to how gsutil does it (http://developers.google.com/storage/docs/gsutil/comm

相关标签:
1条回答
  • 2021-02-10 11:27

    Use the JSON API, there is a copy method. Here is the official example for Python, using the 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)
    
    0 讨论(0)
提交回复
热议问题