-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
Copy pathgcs.py
32 lines (24 loc) · 850 Bytes
/
gcs.py
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
28
29
30
31
32
from google.cloud import storage
GCS_CLIENT = storage.Client()
def create_bucket():
pass
def delete_file(file_path:str):
bucket_name = file_path.split("/")[2]
bucket = GCS_CLIENT.bucket(bucket_name)
blob_path = ''.join(file_path.split("/")[3:])
blob = bucket.blob(blob_path)
blob.delete()
def read_file(file_path:str):
bucket_name = file_path.split("/")[2]
bucket = GCS_CLIENT.bucket(bucket_name)
blob_path = ''.join(file_path.split("/")[3:])
blob = bucket.blob(blob_path)
data = ""
with blob.open("r") as f:
data = f.read()
return data
def upload_file(bucket_name: str, file_path:str, destination_name: str):
bucket = GCS_CLIENT.bucket(bucket_name)
blob = bucket.blob(destination_name)
blob.upload_from_filename(file_path)
print("Uploaded to", destination_name)