• Installed Python 3.7.2 • Created GCP service account and given owner role to it, also enabled storage API and created a cloud storage bucket • Now I’m trying to upload files to GCP cloud storage folder using python script but I couldn’t. But, by using the same structure, I’m able to create new cloud storage bucket and able to edit existing files in it • Here with have attached pythonscript
Ref used: https://googleapis.github.io/google-cloud-python/latest/storage/blobs.html https://cloud.google.com/storage/docs/uploading-objects#storage-upload-object-python
from google.cloud import storage
bucket_name='buckettest'
source_file_name='D:/file.txt'
source_file_name1='D:/jenkins structure.png'
destination_blob_name='test/'
def upload_blob(bucket_name, source_file_name, destination_blob_name):
"""Uploads a file to the bucket."""
client = storage.Client.from_service_account_json('D:\gmailseviceaccount.json')
bucket = client.create_bucket('bucketcreate')
bucket = client.get_bucket(bucket_name)
blob = bucket.blob(destination_blob_name)
blob.upload_from_filename(source_file_name)
blob.upload_from_filename(source_file_name1)
print('File {} uploaded to {}.'.format(
source_file_name,
destination_blob_name))
if __name__ == '__main__':
upload_blob(bucket_name, source_file_name, destination_blob_name)