Skip to content
This repository was archived by the owner on Sep 20, 2023. It is now read-only.

Commit 7f7f541

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 1a2bcc2 commit 7f7f541

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

samples/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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy