Skip to content

Instantly share code, notes, and snippets.

@prl900
Created March 13, 2019 02:56
Show Gist options
  • Save prl900/eac2a2b5e43248ec87dc66c7a176e8ab to your computer and use it in GitHub Desktop.
Save prl900/eac2a2b5e43248ec87dc66c7a176e8ab to your computer and use it in GitHub Desktop.
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