@@ -56,12 +56,12 @@ def upload_directory(self, directory, **options):
5656
5757 try :
5858 for file in files :
59- self .s3 .upload_file (join (directory , file ), bucket_name , join (folder , file ))
59+ self .s3 .upload_file (join (directory , file ), bucket_name , join (folder , file ). replace ( " \\ " , "/" ) )
6060 except self .err as e :
6161 logging .error (e )
6262 raise RuntimeError (e )
6363
64- logging .info ("The " + directory + " directory was uploaded to Amazon S3 successfully" )
64+ logging .info ("The {} directory was uploaded to Amazon S3 successfully" . format ( directory ) )
6565
6666 def download (self , filename = None , ** options ):
6767 bucket_name = options .pop ('bucket_name' , None )
@@ -87,6 +87,8 @@ def download(self, filename=None, **options):
8787
8888
8989class GCS (Clouds ):
90+ CLIENT = None
91+
9092 def __init__ (self , ** options ):
9193 """
9294 @TODO: add documentation
@@ -96,27 +98,27 @@ def __init__(self, **options):
9698 except ImportError as e :
9799 raise ImportError ("No specified import name! make sure that you have installed the package via pip:\n \n "
98100 "pip install google-cloud-storage" )
99- self . client = storage .Client (** options )
101+ GCS . CLIENT = storage .Client (** options )
100102
101103 def upload_directory (self , directory , ** options ):
102104 bucket_name = options .pop ('bucket_name' , None )
103105 if bucket_name is None :
104106 raise ValueError ('You should pass a bucket name' )
105107
106- bucket = self . client .get_bucket (bucket_name )
107-
108+ bucket = GCS . CLIENT .get_bucket (bucket_name )
109+ folder = options . pop ( 'folder' , '' )
108110 files = [f for f in listdir (directory ) if isfile (join (directory , f ))]
109111
110112 for file in files :
111- blob = bucket .blob (bucket_name + file , ** options )
113+ blob = bucket .blob (join ( folder , file ). replace ( " \\ " , "/" ) , ** options )
112114 blob .upload_from_filename (join (directory , file ))
113115
114116 def download (self , filename = None , ** options ):
115117 bucket_name = options .pop ('bucket_name' , None )
116118 if bucket_name is None :
117119 raise ValueError ('You should pass a bucket name' )
118120
119- bucket = self . client .get_bucket (bucket_name )
121+ bucket = GCS . CLIENT .get_bucket (bucket_name )
120122 object_name = options .pop ('object_name' , None )
121123
122124 if object_name is None :
@@ -126,7 +128,7 @@ def download(self, filename=None, **options):
126128 with tempfile .NamedTemporaryFile (prefix = basename (object_name ), delete = False ) as tmp :
127129 filename = tmp .name
128130
129- blob = bucket .get_blob (object_name , options )
131+ blob = bucket .get_blob (object_name , ** options )
130132 blob .download_to_filename (filename )
131133
132134 return filename
0 commit comments