Skip to content

Commit

Permalink
fix: added if statement to filter out dir blob files (#63)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
munkhuushmgl authored and holtskinner committed Jan 3, 2023
1 parent 7cd4615 commit 666a7ff
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion batch_process_documents_sample_v1beta3.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,12 @@ def batch_process_documents(

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

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

# 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
Expand Down

0 comments on commit 666a7ff

Please sign in to comment.