Complete the code to create a new Cloud Storage bucket named 'my-bucket'.
from google.cloud import storage client = storage.Client() bucket = client.[1]('my-bucket')
The create_bucket method creates a new bucket in Cloud Storage.
Complete the code to upload a file 'photo.jpg' to the bucket under the name 'images/photo.jpg'.
bucket = client.get_bucket('my-bucket') blob = bucket.blob('[1]') blob.upload_from_filename('photo.jpg')
The blob name is the path inside the bucket. 'images/photo.jpg' places the file in the 'images' folder.
Fix the error in the code to download the file 'images/photo.jpg' from the bucket to local file 'downloaded.jpg'.
bucket = client.get_bucket('my-bucket') blob = bucket.blob('images/photo.jpg') blob.[1]('downloaded.jpg')
The correct method to download a blob to a local file is download_to_filename.
Fill both blanks to list all bucket names in the project.
buckets = client.[1]() for bucket in buckets: print(bucket.[2])
list_buckets() returns all buckets. Each bucket's name is printed.
Fill all three blanks to create a bucket, upload a file, and print the public URL.
bucket = client.[1]('my-new-bucket') blob = bucket.blob('[2]') blob.upload_from_filename('document.pdf') print(blob.[3])
Use create_bucket to make the bucket, the blob name is the filename, and public_url gives the file's URL.