GCP coding
from google.cloud import storage
Initialize a client
client = storage.Client()
Define the name of the target bucket
bucket_name = 'your-bucket-name'
Define the local file to upload
local_file_path = 'local-file.txt'
Define the remote object name (the name it will have in the bucket)
remote_object_name = 'remote-file.txt'
Get the bucket
bucket = client.get_bucket(bucket_name)
Create a blob (object) in the bucket
blob = bucket.blob(remote_object_name)
Upload the file to the cloud
blob.upload_from_filename(local_file_path)
print(f'File {local_file_path} uploaded to {bucket_name}/{remote_object_name}')
from google.cloud import storage
Initialize a client
client = storage.Client()
Define the name of the target bucket
bucket_name = 'your-bucket-name'
Define the local file to upload
local_file_path = 'local-file.txt'
Define the remote object name (the name it will have in the bucket)
remote_object_name = 'remote-file.txt'
Get the bucket
bucket = client.get_bucket(bucket_name)
Create a blob (object) in the bucket
blob = bucket.blob(remote_object_name)
Upload the file to the cloud
blob.upload_from_filename(local_file_path)
print(f'File {local_file_path} uploaded to {bucket_name}/{remote_object_name}')
No answers yet!
2 years ago by Brollyacademy