in infra-as-code/modules/audio-data-format-change/function-source-code/lib.py [0:0]
def upload_to_gcs(self, bucket_name, filename):
"""Uploads a resource to GCS
Args:
bucket_name (string): Bucket ID where the filename needs to be uploaded
filename (string): The name of the local file to upload
"""
try:
bucket = self.storage_client.bucket(bucket_name)
blob_name = f'{self.get_file_creation_date()}/{filename}'
blob = bucket.blob(blob_name)
path_to_file = '/tmp/'+filename
if os.path.isfile(path_to_file):
blob.upload_from_filename(path_to_file)
print('Uploaded file into gcs')
except Exception as e:
raise e