Complete the code to create a new storage bucket in Google Cloud Storage.
from google.cloud import storage client = storage.Client() bucket = client.[1]('my-new-bucket')
The create_bucket method creates a new bucket in Google Cloud Storage.
Complete the code to upload a file to a bucket as an object.
bucket = client.get_bucket('my-existing-bucket') blob = bucket.blob('folder/myfile.txt') blob.[1]('localfile.txt')
The upload_from_filename method uploads a local file to the blob (object) in the bucket.
Fix the error in the code to list all objects in a bucket.
bucket = client.get_bucket('my-bucket') blobs = bucket.[1]() for blob in blobs: print(blob.name)
The correct method to list objects in a bucket is list_blobs.
Fill both blanks to delete an object from a bucket.
bucket = client.get_bucket('my-bucket') blob = bucket.[1]('my-object.txt') blob.[2]()
Use get_blob to get the object, then delete to remove it.
Fill all three blanks to copy an object to another bucket.
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)
First get the source object with get_blob, then use copy_to to copy it to the destination blob. Finally, print the destination blob's name.
