Простейшим является подкласс storages.backends.s3boto.S3BotoStorage
ввести требуемое поведение
from storages.backends.s3boto import S3BotoStorage
class MyS3Storage(S3BotoStorage):
def _save(self, name, content):
cleaned_name = self._clean_name(name)
name = self._normalize_name(cleaned_name)
_type, encoding = mimetypes.guess_type(name)
content_type = getattr(content, 'content_type',
_type or self.key_class.DefaultContentType)
# setting the content_type in the key object is not enough.
self.headers.update({'Content-Type': content_type})
if re.match('some pattern', cleaned_name) :
self.headers.update({'new custome header': 'value'})
if content_type == 'my/content_type':
self.headers.update({'new custome header': 'value'})
return super(MyS3Storage, self)._save(name, content)
Не забудьте изменить настройки и изменить определение для хранения файлов.
DEFAULT_FILE_STORAGE = 'myapp.MyS3Storage'
Приведенный выше код в основном из S3BotoStorage класса с нашего кода просто проверяя тип содержимого и имя, чтобы добавить пользовательские заголовки.
привет @anurag, сделали мой ответ на который Флит дали щедроты работать для вас, а? – e4c5