From 8e025805a65de2fe7fc83df5fa43e3e7fa0d21e0 Mon Sep 17 00:00:00 2001 From: Jacob Chencha Date: Wed, 10 Jul 2024 13:29:26 +0100 Subject: [PATCH] DOC: Added example for downloading a PDF from Google Cloud Storage (#2745) --- docs/user/streaming-data.md | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/docs/user/streaming-data.md b/docs/user/streaming-data.md index 3b044ddec..b09ab4382 100644 --- a/docs/user/streaming-data.md +++ b/docs/user/streaming-data.md @@ -73,4 +73,18 @@ obj = s3.get_object(Body=csv_buffer.getvalue(), Bucket="my-bucket", Key="my/doc. reader = PdfReader(BytesIO(obj["Body"].read())) ``` -It works similarly for Google Cloud Storage ([example](https://stackoverflow.com/a/68403628/562769)). +To use with Google Cloud storage: + +```python +from io import BytesIO + +from google.cloud import storage + +# os.environ["GOOGLE_APPLICATION_CREDENTIALS"] must be set +storage_client = storage.Client() +blob = storage_client.bucket("my-bucket").blob("mydoc.pdf") +file_stream = BytesIO() +blob.download_to_file(file_stream) +reader = PdfReader(file_stream) +``` +