__init___42.py 1.1 KB

1234567891011121314151617181920212223242526272829
  1. def upload_file(
  2. self, filename, bucket, key, callback=None, extra_args=None
  3. ):
  4. """Upload a file to an S3 object.
  5. Variants have also been injected into S3 client, Bucket and Object.
  6. You don't have to use S3Transfer.upload_file() directly.
  7. """
  8. if extra_args is None:
  9. extra_args = {}
  10. self._validate_all_known_args(extra_args, self.ALLOWED_UPLOAD_ARGS)
  11. events = self._client.meta.events
  12. events.register_first(
  13. 'request-created.s3',
  14. disable_upload_callbacks,
  15. unique_id='s3upload-callback-disable',
  16. )
  17. events.register_last(
  18. 'request-created.s3',
  19. enable_upload_callbacks,
  20. unique_id='s3upload-callback-enable',
  21. )
  22. if (
  23. self._osutil.get_file_size(filename)
  24. >= self._config.multipart_threshold
  25. ):
  26. self._multipart_upload(filename, bucket, key, callback, extra_args)
  27. else:
  28. self._put_object(filename, bucket, key, callback, extra_args)