0
0
GCPcloud~10 mins

Buckets and objects concept in GCP - Interactive Code 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 storage bucket in Google Cloud Storage.

GCP
from google.cloud import storage

client = storage.Client()
bucket = client.[1]('my-new-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 lists all buckets but does not create one.
delete_bucket removes a bucket, not creates it.
2fill in blank
medium

Complete the code to upload a file to a bucket as an object.

GCP
bucket = client.get_bucket('my-existing-bucket')
blob = bucket.blob('folder/myfile.txt')
blob.[1]('localfile.txt')
Drag options to blanks, or click blank then click option'
Aupload_from_filename
Bcopy_to
Cdelete
Ddownload_to_filename
Attempts:
3 left
💡 Hint
Common Mistakes
Using download_to_filename downloads the object instead of uploading.
delete removes the object, not uploads.
copy_to copies an object, not uploads a local file.
3fill in blank
hard

Fix the error in the code to list all objects in a bucket.

GCP
bucket = client.get_bucket('my-bucket')
blobs = bucket.[1]()
for blob in blobs:
    print(blob.name)
Drag options to blanks, or click blank then click option'
Aget_objects
Bget_blobs
Clist_objects
Dlist_blobs
Attempts:
3 left
💡 Hint
Common Mistakes
Using get_blobs or get_objects causes errors because these methods do not exist.
list_objects is not a valid method in this client library.
4fill in blank
hard

Fill both blanks to delete an object from a bucket.

GCP
bucket = client.get_bucket('my-bucket')
blob = bucket.[1]('my-object.txt')
blob.[2]()
Drag options to blanks, or click blank then click option'
Ablob
Bdelete
Cget_blob
Dupload_from_filename
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'blob' instead of 'get_blob' will cause errors.
Using 'upload_from_filename' does not delete objects.
5fill in blank
hard

Fill all three blanks to copy an object to another bucket.

GCP
source_bucket = client.get_bucket('source-bucket')
source_blob = source_bucket.[1]('file.txt')
destination_bucket = client.get_bucket('destination-bucket')
destination_blob = destination_bucket.blob('file.txt')
source_blob.[2](destination_blob)
print('File copied to', [3].name)
Drag options to blanks, or click blank then click option'
Aget_blob
Bcopy_to
Cdestination_blob
Dupload_from_filename
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'upload_from_filename' instead of 'copy_to' will not copy the object.
Printing the source blob's name instead of destination blob's name is incorrect.