Skip to content

Commit

Permalink
add default content type support to S3 backend
Browse files Browse the repository at this point in the history
  • Loading branch information
meeb committed Aug 30, 2024
1 parent d163705 commit fa0c0a1
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,8 @@ by `django-distill` are:
'ACCESS_KEY_ID': '...',
'SECRET_ACCESS_KEY': '...',
'BUCKET': '...',
'ENDPOINT_URL': 'https://.../', # Optional, set to use a different S3 endpoint
'DEFAULT_CONTENT_TYPE': 'application/octet-stream', # Optional
},
```

Expand Down
3 changes: 2 additions & 1 deletion django_distill/backends/amazon_s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,10 @@ def compare_file(self, local_name, remote_name):
return local_hash == obj['ETag'][1:-1]

def upload_file(self, local_name, remote_name):
default_content_type = self.options.get('DEFAULT_CONTENT_TYPE', 'application/octet-stream')
content_type, _ = mimetypes.guess_type(local_name)
if content_type is None:
content_type = 'application/octet-stream'
content_type = default_content_type
extra_args = {'ContentType': content_type}
self.d['connection'].upload_file(local_name, self.d['bucket'], remote_name, ExtraArgs=extra_args)

Expand Down

0 comments on commit fa0c0a1

Please sign in to comment.