Skip to content Skip to sidebar Skip to footer

Programmatically Emulating "gsutil Mv" On Appengine Cloudstorage In Python

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/command

Solution 1:

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)

Post a Comment for "Programmatically Emulating "gsutil Mv" On Appengine Cloudstorage In Python"