s3_service_1.py 674 B

12345678910111213141516171819202122
  1. def upload_object(self, file_name, object_name, expiration_time):
  2. """
  3. Upload a file to an S3 bucket
  4. :param file_name:
  5. :param object_name:
  6. :param expiration_time:
  7. :return: url as string of the presigned url
  8. """
  9. try:
  10. key_prefix = str(uuid.uuid4())
  11. self.s3.upload_file(
  12. file_name, self.bucket_name, f"{key_prefix}/{object_name}",
  13. )
  14. return self.__generate_pre_signed_url(
  15. expiration_time, object_name, key_prefix
  16. )
  17. except ClientError as client_error:
  18. logger.exception(
  19. NOT_AVAILABLE, client_error,
  20. )
  21. raise InternalServerError(NOT_AVAILABLE)