in ez_wsi_dicomweb/gcs_image.py [0:0]
def _get_gcs_image(self) -> _GcsImageState:
"""Returns image width, height, bytes, and icc profile."""
with self._gcs_image_lock:
if self._image_bytes is not None:
return _GcsImageState(
self._width,
self._height,
self._image_bytes,
self._icc_color_profile,
)
try:
credentials = self.credentials
if not credentials.token or isinstance(
self._credential_factory,
credential_factory_module.NoAuthCredentialsFactory,
):
client = google.cloud.storage.Client.create_anonymous_client()
else:
client = google.cloud.storage.Client(credentials=self.credentials)
gcs_blob = google.cloud.storage.Blob.from_string(
self._gcs_uri,
client=client,
)
raw_bytes = gcs_blob.download_as_bytes(raw_download=True)
except google.api_core.exceptions.GoogleAPICallError as exp:
raise ez_wsi_errors.raise_ez_wsi_http_exception(exp.message, exp)
self._init_compressed_image_bytes(raw_bytes)
return _GcsImageState(
self._width, self._height, self._image_bytes, self._icc_color_profile
)