Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a new Cloud Storage bucket named 'my-bucket'.
GCP
from google.cloud import storage client = storage.Client() bucket = client.create_bucket('[1]')
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting quotes around the bucket name
Using an incorrect bucket name
✗ Incorrect
The bucket name must be a string. Here, 'my-bucket' is the correct name to create.
2fill in blank
mediumComplete the code to upload a file 'photo.jpg' to the bucket.
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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different file name than the one uploaded
Missing quotes around the blob name
✗ Incorrect
The blob name should match the file name you want to upload, which is 'photo.jpg'.
3fill in blank
hardFix the error in the code to download 'photo.jpg' from the bucket to local file 'downloaded.jpg'.
GCP
bucket = client.get_bucket('my-bucket') blob = bucket.blob('photo.jpg') blob.[1]('downloaded.jpg')
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using upload methods instead of download
Mixing method names
✗ Incorrect
To download a file from Cloud Storage, use download_to_filename.
4fill in blank
hardFill both blanks to list all blobs in 'my-bucket' and print their names.
GCP
bucket = client.get_bucket('my-bucket') blobs = bucket.[1]() for blob in blobs: print(blob.[2])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect method names
Using wrong attribute for blob name
✗ Incorrect
Use list_blobs() to get blobs and name to get each blob's name.
5fill in blank
hardFill all three blanks to delete a blob named 'old_file.txt' from 'my-bucket'.
GCP
bucket = client.get_bucket('[1]') blob = bucket.blob('[2]') blob.[3]()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong method name like 'remove'
Mixing bucket or blob names
✗ Incorrect
To delete a file, get the bucket and blob by name, then call delete().