Created
March 13, 2019 02:56
-
-
Save prl900/eac2a2b5e43248ec87dc66c7a176e8ab to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from google.cloud import storage | |
from glob import glob | |
from os.path import basename, join | |
gsbucket = "nsw_water_compliance" | |
def upload_files(gsbucket, dst_path, src_path, wildcard="*"): | |
storage_client = storage.Client() | |
bucket = storage_client.bucket(gsbucket) | |
file_paths = glob("{}/{}".format(src_path, wildcard)) | |
print("{}/{}".format(src_path, wildcard)) | |
print(file_paths) | |
for file_path in file_paths: | |
blob = bucket.blob(join(dst_path, basename(file_path))) | |
blob.upload_from_filename(file_path) | |
def list_objects(gsbucket, dst_path): | |
storage_client = storage.Client() | |
bucket = storage_client.bucket(gsbucket) | |
blobs = bucket.list_blobs(prefix=dst_path) | |
return [str(blob.name) for blob in blobs] | |
if __name__ == "__main__": | |
upload_files(gsbucket, "myfolder", "/path/to/source", wildcard="*.jpg") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment