google_cloud_service_4.py 731 B

123456789101112131415161718
  1. def upload_files(self, list_of_files):
  2. self.count = 0
  3. print("Sample of file to be uploaded to Google storage are \t {}".format(
  4. list_of_files))
  5. bucket = self.__storage_client.get_bucket(self.__bucket)
  6. for each_file in tqdm(list_of_files):
  7. try:
  8. blob_name = os.path.split(each_file)[-1]
  9. blob = bucket.blob(blob_name)
  10. blob.upload_from_filename(
  11. each_file) # .upload_file from google cloud api package uploads file to google storage
  12. self.count += 1
  13. except Exception as e:
  14. print("Failed to upload file {} \n{}".format(each_file, e))
  15. print("Total file succefully uploaded:\t {}".format(self.count))
  16. return True