-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathuploading.py
More file actions
27 lines (20 loc) · 759 Bytes
/
uploading.py
File metadata and controls
27 lines (20 loc) · 759 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import os
from google.cloud import storage
os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = 'ServiceKeyGoogleCloud.json'
storage_client = storage.Client()
##
## THIS CODE UPLOADS A FILE TO THE TEST TRANSFERS FOLDER IN KYS_DATA_BUCKET
##
my_bucket = storage_client.get_bucket('kys_data_bucket')
def upload_to_bucket(blob_name, path, bucket_name):
try:
bucket = storage_client.get_bucket(bucket_name)
blob = bucket.blob(blob_name)
blob.upload_from_filename(path)
return True
except Exception as e:
print(e)
return False
# Test Code
# file_path = 'C:/Users/Lenovo/Desktop/Python Projects/SocStream'
# upload_to_bucket('TestTransfers/TestFile', os.path.join(file_path,'TestFile.txt'),'kys_data_bucket')