Skip to content

Commit 03280fa

Browse files
authored
Update list blobs to use new client.list_blobs() method. (#2296)
* Update list blob samples * Update requirements.txt * Fix lint issues * Use latest storage client
1 parent 09f7eb4 commit 03280fa

File tree

2 files changed

+4
-7
lines changed

2 files changed

+4
-7
lines changed

storage/cloud-client/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
google-cloud-pubsub==0.39.1
2-
google-cloud-storage==1.15.0
2+
google-cloud-storage==1.17.0

storage/cloud-client/snippets.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,7 @@ def list_buckets():
113113
def list_blobs(bucket_name):
114114
"""Lists all the blobs in the bucket."""
115115
storage_client = storage.Client()
116-
bucket = storage_client.get_bucket(bucket_name)
117-
118-
blobs = bucket.list_blobs()
116+
blobs = storage_client.list_blobs(bucket_name)
119117

120118
for blob in blobs:
121119
print(blob.name)
@@ -144,9 +142,8 @@ def list_blobs_with_prefix(bucket_name, prefix, delimiter=None):
144142
145143
"""
146144
storage_client = storage.Client()
147-
bucket = storage_client.get_bucket(bucket_name)
148-
149-
blobs = bucket.list_blobs(prefix=prefix, delimiter=delimiter)
145+
blobs = storage_client.list_blobs(bucket_name, prefix=prefix,
146+
delimiter=delimiter)
150147

151148
print('Blobs:')
152149
for blob in blobs:

0 commit comments

Comments
 (0)