dav2s3_14.py 980 B

12345678910111213141516171819
  1. def upload(self, source_path, target_path=''):
  2. """Upload all files from given path to given bucket."""
  3. source_path = join(self.path, source_path)
  4. if target_path.find('/') == 0:
  5. target_path = target_path[1:]
  6. if target_path.find('/') == -1 or target_path.rfind('/') == len(target_path)-1:
  7. target_path = target_path+'/'
  8. bucket = self.get_bucket()
  9. if bucket:
  10. files = [f for f in listdir(source_path) if isfile(join(source_path, f))]
  11. for _file in files:
  12. self.verbose_print("Uploading: "+str(target_path)+str(_file))
  13. try:
  14. data = open(source_path+'/'+str(_file), 'rb')
  15. bucket.put_object(Key=str(target_path)+str(_file), Body=data)
  16. except Exception as e:
  17. print("Error during upload of "+str(target_path)+str(_file)+": "+str(e))
  18. return False
  19. return True