Skip to content
This repository was archived by the owner on Mar 6, 2026. It is now read-only.

Commit 6d16a7d

Browse files
committed
Run different methods depending on package version
1 parent 61414e0 commit 6d16a7d

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

google/cloud/documentai_toolbox/utilities/gcs_utilities.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#
1616
"""Google Cloud Storage utilities."""
1717
import os
18+
import pkg_resources
1819
import re
1920
from typing import Dict, List, Optional, Tuple
2021

@@ -142,7 +143,18 @@ def get_blob(
142143
if not re.match(constants.FILE_CHECK_REGEX, gcs_uri):
143144
raise ValueError("gcs_uri must link to a single file.")
144145

145-
return storage.Blob.from_uri(gcs_uri, _get_storage_client(module=module))
146+
try:
147+
version = pkg_resources.get_distribution("google-cloud-storage").version
148+
except pkg_resources.DistributionNotFound:
149+
raise ImportError("google-cloud-storage is not installed.")
150+
151+
client = _get_storage_client(module=module)
152+
153+
major, _, _ = map(int, version.split("."))
154+
if major < 3:
155+
return storage.Blob.from_string(gcs_uri, client)
156+
else:
157+
return storage.Blob.from_uri(gcs_uri, client)
146158

147159

148160
def split_gcs_uri(gcs_uri: str) -> Tuple[str, str]:

0 commit comments

Comments
 (0)