Niklas B
Niklas B

Reputation: 1969

Google Cloud Storage Python API: blob rename, where is copy_to

I am trying to rename a blob (which can be quite large) after having uploaded them to a temporary location in the bucket.

Reading the documentation it says:

Warning: This method will first duplicate the data and then delete the old blob. This means that with very large objects renaming could be a very (temporarily) costly or a very slow operation. If you need more control over the copy and deletion, instead use google.cloud.storage.blob.Blob.copy_to and google.cloud.storage.blob.Blob.delete directly.

But I can find absolutely no reference to copy_to anywhere in the SDK (or elsewhere really).

Is there any way to rename a blob from A to B without the SDK copying the file. In my case overwriting B, but I can remove B first if it's easier.

The reason is checksum validation, I'll upload it under A first to make sure it's successfully uploaded (and doesn't trigger DataCorruption) and only then replace B (the live object)

Upvotes: 0

Views: 289

Answers (1)

David
David

Reputation: 9721

GCS itself does not support renaming objects. Renaming with a copy+delete is done in the client as a helper, and there is no better way to rename an object at the moment.

As you say your goal is checksum validation, there is a better solution. Upload directly to your destination and use GCS's built in checksum verification. How you do this depends on the API:

  • JSON objects.insert: Set crc32c or md5Hash header.
  • XML PUT object: Set x-goog-hash header.
  • Python SDK Blob.upload_from_* methods: Set checksum="crc32c" or checksum="md5" method parameter.

Upvotes: 1

Related Questions