Skip to content

Commit

Permalink
fix: add a comment to draw attention to using get_blob, not blob (Goo…
Browse files Browse the repository at this point in the history
…gleCloudPlatform#5052)

* fix: add a comment to draw attention to using get_blob, not blob

* docs: further elaboration

* docs: add clarifying doc string to download file

* Update storage_download_file.py

* Update storage_download_file.py
  • Loading branch information
crwilcox authored Dec 9, 2020
1 parent 1dc223b commit c55cd88
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
5 changes: 5 additions & 0 deletions storage/cloud-client/storage_download_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ def download_blob(bucket_name, source_blob_name, destination_file_name):
storage_client = storage.Client()

bucket = storage_client.bucket(bucket_name)

# Construct a client side representation of a blob.
# Note `Bucket.blob` differs from `Bucket.get_blob` as it doesn't retrieve
# any content from Google Cloud Storage. As we don't need additional data,
# using `Bucket.blob` is preferred here.
blob = bucket.blob(source_blob_name)
blob.download_to_filename(destination_file_name)

Expand Down
4 changes: 4 additions & 0 deletions storage/cloud-client/storage_get_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ def blob_metadata(bucket_name, blob_name):

storage_client = storage.Client()
bucket = storage_client.bucket(bucket_name)

# Retrieve a blob, and its metadata, from Google Cloud Storage.
# Note that `get_blob` differs from `Bucket.blob`, which does not
# make an HTTP request.
blob = bucket.get_blob(blob_name)

print("Blob: {}".format(blob.name))
Expand Down

0 comments on commit c55cd88

Please sign in to comment.