|
15 | 15 |
|
16 | 16 | import boto3
|
17 | 17 | from botocore.client import Config
|
| 18 | +from boto3.s3.transfer import TransferConfig |
18 | 19 | from botocore.exceptions import ClientError
|
19 | 20 | from django.conf import settings
|
20 | 21 | from django.contrib.staticfiles.storage import ManifestFilesMixin
|
@@ -149,7 +150,8 @@ class S3Storage(Storage):
|
149 | 150 | "AWS_S3_KMS_ENCRYPTION_KEY_ID": "",
|
150 | 151 | "AWS_S3_GZIP": True,
|
151 | 152 | "AWS_S3_SIGNATURE_VERSION": "s3v4",
|
152 |
| - "AWS_S3_FILE_OVERWRITE": False |
| 153 | + "AWS_S3_FILE_OVERWRITE": False, |
| 154 | + "AWS_S3_USE_THREADS": True, |
153 | 155 | }
|
154 | 156 |
|
155 | 157 | s3_settings_suffix = ""
|
@@ -188,6 +190,8 @@ def _setup(self):
|
188 | 190 | )
|
189 | 191 | # Create a thread-local connection manager.
|
190 | 192 | self._connections = _Local(self)
|
| 193 | + # Set transfer config for S3 operations |
| 194 | + self._transfer_config = TransferConfig(use_threads=self.settings.AWS_S3_USE_THREADS) |
191 | 195 |
|
192 | 196 | @property
|
193 | 197 | def s3_connection(self):
|
@@ -326,7 +330,7 @@ def _save(self, name, content):
|
326 | 330 | content.seek(0)
|
327 | 331 | # Save the file.
|
328 | 332 | self.s3_connection.upload_fileobj(content, put_params.pop('Bucket'), put_params.pop('Key'),
|
329 |
| - ExtraArgs=put_params) |
| 333 | + ExtraArgs=put_params, Config=self._transfer_config) |
330 | 334 | # Close all temp files.
|
331 | 335 | for temp_file in temp_files:
|
332 | 336 | temp_file.close()
|
|
0 commit comments