s3_upload_3.py 977 B

1234567891011121314151617181920
  1. def _upload_file_to_s3(self, local_file, bucket, s3_file=None):
  2. if not s3_file:
  3. s3_file = os.path.basename(local_file)
  4. if os.path.getsize(local_file) < 1073741824: # File size is less than a gig
  5. try:
  6. self.s3.upload_file(local_file, bucket, s3_file)
  7. logger.info("\nUploaded {} to S3".format(local_file))
  8. except FileNotFoundError:
  9. logger.error("\nThe file {} was not found".format(local_file))
  10. except NoCredentialsError:
  11. logger.error("\nCredentials not available")
  12. else:
  13. try:
  14. self._multipart_upload(local_file, bucket, s3_file)
  15. logger.info("\nUploaded {} to S3".format(local_file))
  16. except FileNotFoundError:
  17. logger.error("\nThe file {} was not found".format(local_file))
  18. except NoCredentialsError:
  19. logger.error("\nCredentials not available")