-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcloud.py
More file actions
27 lines (21 loc) · 921 Bytes
/
cloud.py
File metadata and controls
27 lines (21 loc) · 921 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
from config import MyFile, IS_CLOUD, BUCKET_NAME
from google.cloud import storage
def upload_file_to_cloud_storage(file: MyFile) -> None:
"""Helper that works both locally and in cloud, can be used for testing."""
if not IS_CLOUD:
print(f"[LOCAL MODE] Would upload {file}")
return
client = storage.Client()
bucket = client.bucket(BUCKET_NAME)
blob: storage.Blob = bucket.blob(file.name)
blob.upload_from_filename(file.path)
print(f"Uploaded {file} to {BUCKET_NAME}")
def upload_string_to_cloud_storage(output_file: str, string: str) -> None:
if not IS_CLOUD:
print(f"[LOCAL MODE] Would upload {output_file}")
return
client = storage.Client()
bucket = client.bucket(BUCKET_NAME)
blob: storage.Blob = bucket.blob(output_file)
blob.upload_from_string(string, content_type="text/html")
print(f"Uploaded {output_file} to {BUCKET_NAME}")