I'm new to GCP and GCP Storage. I want to upload files from File System on PC to GCS bucket. I found following code and altering it.
But I have files that sit in folder like this: \F1\Data\Export\PlayOnUsers\2021\12\
That is 2021 year and 12 month - December
So after \F1\Data\Export\PlayOnUsers\
it's changing.
I need to put in similar format to GCS. I need to create sub-buckets 2021\
and 12\
How is this done? I also don't see the part where you put CREDENTIALS FOR GCS
I have this code so far:
from google.cloud import storage
def upload_blob(bucket_name, source_file_name, destination_blob_name):
"""Uploads a file to the bucket."""
# The ID of your GCS bucket
bucket_name = "MyBucket-scv"
# The path to your file to upload
source_file_name = "F1/Data/Export"
# The ID of your GCS object
destination_blob_name = "storage-object-name"
storage_client = storage.Client()
bucket = storage_client.bucket(bucket_name)
blob = bucket.blob(destination_blob_name)
blob.upload_from_filename(source_file_name)
print(
"File {} uploaded to {}.".format(
source_file_name, destination_blob_name
)
)
upload_blob(.., .., ..)
# how do I pass parameters automated when calling the function?