-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
32241e0
commit f7ff963
Showing
2 changed files
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import tempfile | ||
import os | ||
|
||
from google.auth.credentials import AnonymousCredentials | ||
from google.cloud import storage | ||
|
||
# This endpoint assumes that you are using the default port 4443 from the container. | ||
# If you are using a different port, please set the environment variable STORAGE_EMULATOR_HOST. | ||
os.environ.setdefault("STORAGE_EMULATOR_HOST", "http://localhost:4443") | ||
|
||
|
||
client = storage.Client( | ||
credentials=AnonymousCredentials(), | ||
project="test", | ||
# Alternatively instead of using the global env STORAGE_EMULATOR_HOST. You can define it here. | ||
# This will set this client object to point to the local google cloud storage. | ||
# client_options={"api_endpoint": "http://localhost:4443"}, | ||
) | ||
|
||
# List the Buckets | ||
for bucket in client.list_buckets(): | ||
print(f"Bucket: {bucket.name}\n") | ||
|
||
# List the Blobs in each Bucket | ||
for blob in bucket.list_blobs(): | ||
print(f"Blob: {blob.name}") | ||
|
||
# Print the content of the Blob | ||
b = bucket.get_blob(blob.name) | ||
with tempfile.NamedTemporaryFile() as temp_file: | ||
s = b.download_to_filename(temp_file.name) | ||
temp_file.seek(0, 0) | ||
print(temp_file.read(), "\n") |