1. pydolan
  2. django-storages


echamberlain  committed 3602d34

S3 Content-Type fix.

Boto overwrites the Header Content-Type setting with its own guess. Changed _save to add the Content-Type to the metadata.
The metadata is added to the Header after boto overwrites the Content-Type in the Header.

In the case of uploaded files, the file's content_type is ignored and instead mimetypes.guess_type is used instead.
This fix checks for content.content_type and if present, uses it instead of mimetypes.guess_type.

We needed this fix to properly set the Content-Type when uploading caf files without an extension.

  • Participants
  • Parent commits 4ba0682
  • Branches default

Comments (0)

Files changed (1)

File storages/backends/s3boto.py

View file
  • Ignore whitespace
         cleaned_name = self._clean_name(name)
         name = self._normalize_name(cleaned_name)
         headers = self.headers
-        content_type = mimetypes.guess_type(name)[0] or Key.DefaultContentType            
+        content_type = getattr(content,'content_type', mimetypes.guess_type(name)[0] or Key.DefaultContentType)
         if self.gzip and content_type in self.gzip_content_types:
             content = self._compress_content(content)
             headers.update({'Content-Encoding': 'gzip'})
-        headers.update({
-            'Content-Type': content_type,
-        })
         content.name = cleaned_name
         k = self.bucket.get_key(name)
         if not k:
             k = self.bucket.new_key(name)
+        k.set_metadata('Content-Type',content_type)
         k.set_contents_from_file(content, headers=headers, policy=self.acl, 
         return cleaned_name