Upload a file to an S3 object. Variants have also been injected into S3 client, Bucket and Object. You don't have to use S3Transfer.upload_file() directly.
(
self, filename, bucket, key, callback=None, extra_args=None
)
| 733 | checksum_context["request_algorithm"]["in"] = "header" |
| 734 | |
| 735 | def upload_file( |
| 736 | self, filename, bucket, key, callback=None, extra_args=None |
| 737 | ): |
| 738 | """Upload a file to an S3 object. |
| 739 | |
| 740 | Variants have also been injected into S3 client, Bucket and Object. |
| 741 | You don't have to use S3Transfer.upload_file() directly. |
| 742 | """ |
| 743 | if extra_args is None: |
| 744 | extra_args = {} |
| 745 | self._validate_all_known_args(extra_args, self.ALLOWED_UPLOAD_ARGS) |
| 746 | events = self._client.meta.events |
| 747 | events.register_first( |
| 748 | 'request-created.s3', |
| 749 | disable_upload_callbacks, |
| 750 | unique_id='s3upload-callback-disable', |
| 751 | ) |
| 752 | events.register_last( |
| 753 | 'request-created.s3', |
| 754 | enable_upload_callbacks, |
| 755 | unique_id='s3upload-callback-enable', |
| 756 | ) |
| 757 | if ( |
| 758 | self._osutil.get_file_size(filename) |
| 759 | >= self._config.multipart_threshold |
| 760 | ): |
| 761 | self._multipart_upload(filename, bucket, key, callback, extra_args) |
| 762 | else: |
| 763 | self._put_object(filename, bucket, key, callback, extra_args) |
| 764 | |
| 765 | def _put_object(self, filename, bucket, key, callback, extra_args): |
| 766 | # We're using open_file_chunk_reader so we can take advantage of the |