0
0
GCPcloud~10 mins

Creating buckets and uploading objects in GCP - Interactive Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a new Cloud Storage bucket named 'my-bucket'.

GCP
from google.cloud import storage

client = storage.Client()
bucket = client.[1]('my-bucket')
Drag options to blanks, or click blank then click option'
Acreate_bucket
Bget_bucket
Clist_buckets
Ddelete_bucket
Attempts:
3 left
💡 Hint
Common Mistakes
Using get_bucket instead of create_bucket will try to access an existing bucket.
list_buckets returns all buckets, not create one.
delete_bucket removes a bucket, not create it.
2fill in blank
medium

Complete the code to upload a file 'photo.jpg' to the bucket under the name 'images/photo.jpg'.

GCP
bucket = client.get_bucket('my-bucket')
blob = bucket.blob('[1]')
blob.upload_from_filename('photo.jpg')
Drag options to blanks, or click blank then click option'
Aimages/photo.jpg
Bphoto
Cimages_photo.jpg
Dphoto.jpg
Attempts:
3 left
💡 Hint
Common Mistakes
Using just 'photo.jpg' uploads to the root, not inside 'images' folder.
Using 'photo' misses the file extension.
Using 'images_photo.jpg' is not a valid path with folders.
3fill in blank
hard

Fix the error in the code to download the file 'images/photo.jpg' from the bucket to local file 'downloaded.jpg'.

GCP
bucket = client.get_bucket('my-bucket')
blob = bucket.blob('images/photo.jpg')
blob.[1]('downloaded.jpg')
Drag options to blanks, or click blank then click option'
Adownload_as_string
Bdownload_to_file
Cdownload_to_filename
Dupload_from_filename
Attempts:
3 left
💡 Hint
Common Mistakes
Using upload_from_filename uploads a file instead of downloading.
download_as_string returns bytes, not saving to file.
download_to_file requires a file object, not a filename string.
4fill in blank
hard

Fill both blanks to list all bucket names in the project.

GCP
buckets = client.[1]()
for bucket in buckets:
    print(bucket.[2])
Drag options to blanks, or click blank then click option'
Alist_buckets
Bname
Cid
Dget_bucket
Attempts:
3 left
💡 Hint
Common Mistakes
Using get_bucket tries to get one bucket, not list all.
Using 'id' prints the bucket's id, not the name.
Using 'list_bucket' (missing s) causes error.
5fill in blank
hard

Fill all three blanks to create a bucket, upload a file, and print the public URL.

GCP
bucket = client.[1]('my-new-bucket')
blob = bucket.blob('[2]')
blob.upload_from_filename('document.pdf')
print(blob.[3])
Drag options to blanks, or click blank then click option'
Acreate_bucket
Bdocument.pdf
Cpublic_url
Dget_bucket
Attempts:
3 left
💡 Hint
Common Mistakes
Using get_bucket instead of create_bucket won't create a new bucket.
Using a wrong blob name causes upload errors.
Trying to print blob.name instead of public_url won't show the URL.