-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
23 lines (20 loc) · 688 Bytes
/
utils.py
File metadata and controls
23 lines (20 loc) · 688 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import os
from google.cloud import storage
def download_file(bucket_name, blob_name, local_path):
client = storage.Client()
bucket = client.bucket(bucket_name)
blob = bucket.blob(blob_name)
blob.download_to_filename(local_path)
return local_path
def upload_file(bucket_name, source_path, dest_name):
client = storage.Client()
bucket = client.bucket(bucket_name)
blob = bucket.blob(dest_name)
blob.upload_from_filename(source_path)
return True
def set_metadata(bucket_name, blob_name, metadata):
client = storage.Client()
bucket = client.bucket(bucket_name)
blob = bucket.blob(blob_name)
blob.metadata = metadata
blob.patch()