@@ -434,7 +434,7 @@ def copy_blob(self, blob, destination_bucket, new_name=None,
434
434
client = None ):
435
435
"""Copy the given blob to the given bucket, optionally with a new name.
436
436
437
- :type blob: string or :class:`gcloud.storage.blob.Blob`
437
+ :type blob: :class:`gcloud.storage.blob.Blob`
438
438
:param blob: The blob to be copied.
439
439
440
440
:type destination_bucket: :class:`gcloud.storage.bucket.Bucket`
@@ -461,6 +461,35 @@ def copy_blob(self, blob, destination_bucket, new_name=None,
461
461
new_blob ._set_properties (copy_result )
462
462
return new_blob
463
463
464
+ def rename_blob (self , blob , new_name , client = None ):
465
+ """Rename the given blob using copy and delete operations.
466
+
467
+ Effectively, copies blob to the same bucket with a new name, then
468
+ deletes the blob.
469
+
470
+ .. warning::
471
+
472
+ This method will first duplicate the data and then delete the
473
+ old blob. This means that with very large objects renaming
474
+ could be a very (temporarily) costly or a very slow operation.
475
+
476
+ :type blob: :class:`gcloud.storage.blob.Blob`
477
+ :param blob: The blob to be renamed.
478
+
479
+ :type new_name: string
480
+ :param new_name: The new name for this blob.
481
+
482
+ :type client: :class:`gcloud.storage.client.Client` or ``NoneType``
483
+ :param client: Optional. The client to use. If not passed, falls back
484
+ to the ``client`` stored on the current bucket.
485
+
486
+ :rtype: :class:`Blob`
487
+ :returns: The newly-renamed blob.
488
+ """
489
+ new_blob = self .copy_blob (blob , self , new_name , client = client )
490
+ blob .delete (client = client )
491
+ return new_blob
492
+
464
493
@property
465
494
def cors (self ):
466
495
"""Retrieve CORS policies configured for this bucket.
0 commit comments