@@ -46,7 +46,7 @@ def load_bytes(self, image_string: str) -> bytes:
4646 """
4747
4848 if image_string .startswith ("gs://" ):
49- return self ._bytes_from_gsc (image_string )
49+ return self ._bytes_from_gcs (image_string )
5050
5151 if image_string .startswith ("data:image/" ):
5252 return self ._bytes_from_b64 (image_string )
@@ -115,8 +115,8 @@ def _bytes_from_url(self, url: str) -> bytes:
115115
116116 return response .content
117117
118- def _bytes_from_gsc (self , gcs_uri : str ) -> bytes :
119- """Gets image bytes from a google cloud storage uri.
118+ def _bytes_from_gcs (self , gcs_uri : str ) -> bytes :
119+ """Gets image bytes from a Google Cloud Storage uri.
120120
121121 Args:
122122 gcs_uri: Valid gcs uri.
@@ -129,15 +129,7 @@ def _bytes_from_gsc(self, gcs_uri: str) -> bytes:
129129 """
130130
131131 gcs_client = storage .Client (project = self ._project )
132-
133- pieces = gcs_uri .split ("/" )
134-
135- blobs = list (gcs_client .list_blobs (pieces [2 ], prefix = "/" .join (pieces [3 :])))
136-
137- if len (blobs ) > 1 :
138- raise ValueError (f"Found more than one candidate for { gcs_uri } !" )
139-
140- return blobs [0 ].download_as_bytes ()
132+ return storage .Blob .from_string (gcs_uri , gcs_client ).download_as_bytes ()
141133
142134 def _is_url (self , url_string : str ) -> bool :
143135 """Checks if a url is valid.
0 commit comments