17def upload_csv_to_bucket(bucket_name, source_file_name, destination_blob_name):
19 Upload a CSV file to a Google Cloud Storage bucket.
22 bucket_name: Name of the bucket to upload the file to.
23 source_file_name: Path to the file to upload.
24 destination_blob_name: Name of the file in the bucket.
28 bucket = client.bucket(bucket_name)
29 blob = bucket.blob(destination_blob_name)
30 blob.upload_from_filename(source_file_name)
31 print(f
"File {source_file_name} uploaded to {destination_blob_name}.")
34def download_csv_from_bucket_to_folder(
35 bucket_name, source_blob_name, destination_folder, file_name
38 Download a CSV file from a Google Cloud Storage bucket to a specified folder.
41 bucket_name: Name of the bucket to download the file from.
42 source_blob_name: Name of the file in the bucket.
43 destination_folder: Folder to save the file to.
44 file_name: Name of the file to save.
47 bucket = client.bucket(bucket_name)
48 blob = bucket.blob(source_blob_name)
51 destination_file_path = os.path.join(destination_folder, file_name)
52 os.makedirs(os.path.dirname(destination_file_path), exist_ok=
True)
54 blob.download_to_filename(destination_file_path)
55 print(f
"File {source_blob_name} downloaded to {destination_file_path}.")