@@ -1512,7 +1512,9 @@ def rewrite(self, source, token=None, client=None):
15121512 return api_response ["rewriteToken" ], rewritten , size
15131513
15141514 def update_storage_class (self , new_class , client = None ):
1515- """Update blob's storage class via a rewrite-in-place.
1515+ """Update blob's storage class via a rewrite-in-place. This helper will
1516+ wait for the rewrite to complete before returning, so it may take some
1517+ time for large files.
15161518
15171519 See
15181520 https://cloud.google.com/storage/docs/per-object-storage-class
@@ -1530,25 +1532,13 @@ def update_storage_class(self, new_class, client=None):
15301532 if new_class not in self ._STORAGE_CLASSES :
15311533 raise ValueError ("Invalid storage class: %s" % (new_class ,))
15321534
1533- client = self ._require_client (client )
1534-
1535- query_params = {}
1536-
1537- if self .user_project is not None :
1538- query_params ["userProject" ] = self .user_project
1539-
1540- headers = _get_encryption_headers (self ._encryption_key )
1541- headers .update (_get_encryption_headers (self ._encryption_key , source = True ))
1535+ # Update current blob's storage class prior to rewrite
1536+ self ._patch_property ('storageClass' , new_class )
15421537
1543- api_response = client ._connection .api_request (
1544- method = "POST" ,
1545- path = self .path + "/rewriteTo" + self .path ,
1546- query_params = query_params ,
1547- data = {"storageClass" : new_class },
1548- headers = headers ,
1549- _target_object = self ,
1550- )
1551- self ._set_properties (api_response ["resource" ])
1538+ # Execute consecutive rewrite operations until operation is done
1539+ token , _ , _ = self .rewrite (self )
1540+ while token is not None :
1541+ token , _ , _ = self .rewrite (self , token = token )
15521542
15531543 cache_control = _scalar_property ("cacheControl" )
15541544 """HTTP 'Cache-Control' header for this object.
@@ -1815,7 +1805,7 @@ def kms_key_name(self):
18151805 This can only be set at blob / object **creation** time. If you'd
18161806 like to change the storage class **after** the blob / object already
18171807 exists in a bucket, call :meth:`update_storage_class` (which uses
1818- the "storage.objects. rewrite" method ).
1808+ :meth:` rewrite` ).
18191809
18201810 See https://cloud.google.com/storage/docs/storage-classes
18211811
0 commit comments