Complete the code to create a new Cloud Storage bucket named 'my-bucket'.
from google.cloud import storage client = storage.Client() bucket = client.create_bucket('[1]')
The bucket name must be a string. Here, 'my-bucket' is the correct name to create.
Complete the code to upload a file 'photo.jpg' to the bucket.
bucket = client.get_bucket('my-bucket') blob = bucket.blob('[1]') blob.upload_from_filename('photo.jpg')
The blob name should match the file name you want to upload, which is 'photo.jpg'.
Fix the error in the code to download 'photo.jpg' from the bucket to local file 'downloaded.jpg'.
bucket = client.get_bucket('my-bucket') blob = bucket.blob('photo.jpg') blob.[1]('downloaded.jpg')
To download a file from Cloud Storage, use download_to_filename.
Fill both blanks to list all blobs in 'my-bucket' and print their names.
bucket = client.get_bucket('my-bucket') blobs = bucket.[1]() for blob in blobs: print(blob.[2])
Use list_blobs() to get blobs and name to get each blob's name.
Fill all three blanks to delete a blob named 'old_file.txt' from 'my-bucket'.
bucket = client.get_bucket('[1]') blob = bucket.blob('[2]') blob.[3]()
To delete a file, get the bucket and blob by name, then call delete().
