Skip to content

Commit cfbf114

Browse files
authored
fix: added if statement to filter out dir blob files (#63)
Fixes #62 🦕 Current version of sample doesnt check if blob is directory or .json file. Then, it downloads as bytes and tries to parse json from the dir blob file which will cause error.
1 parent cb39215 commit cfbf114

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

documentai/snippets/batch_process_documents_sample_v1beta3.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,12 @@ def batch_process_documents(
7878

7979
for i, blob in enumerate(blob_list):
8080
# Download the contents of this blob as a bytes object.
81+
if ".json" not in blob.name:
82+
return
83+
# Only parses JSON files
8184
blob_as_bytes = blob.download_as_bytes()
82-
document = documentai.types.Document.from_json(blob_as_bytes)
8385

86+
document = documentai.types.Document.from_json(blob_as_bytes)
8487
print(f"Fetched file {i + 1}")
8588

8689
# For a full list of Document object attributes, please reference this page: https://googleapis.dev/python/documentai/latest/_modules/google/cloud/documentai_v1beta3/types/document.html#Document

0 commit comments

Comments
 (0)