From 6d8be4c07f2d3ae6e6cdfda4d8bff4ad22420820 Mon Sep 17 00:00:00 2001 From: msramalho <19508417+msramalho@users.noreply.github.com> Date: Thu, 14 Jul 2022 18:16:06 +0200 Subject: [PATCH] s3 allow online preview instead of forced download --- storages/s3_storage.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/storages/s3_storage.py b/storages/s3_storage.py index ceb75c1..b124aae 100644 --- a/storages/s3_storage.py +++ b/storages/s3_storage.py @@ -1,4 +1,4 @@ -import uuid, os +import uuid, os, mimetypes from dataclasses import dataclass import boto3 @@ -21,6 +21,7 @@ class S3Config: private: bool = False key_path: str = "default" # 'default' uses full naming, 'random' uses generated uuid + class S3Storage(Storage): def __init__(self, config: S3Config): @@ -70,4 +71,5 @@ class S3Storage(Storage): extra_args = kwargs.get("extra_args", {}) else: extra_args = kwargs.get("extra_args", {'ACL': 'public-read'}) + extra_args['ContentType'] = mimetypes.guess_type(key)[0] self.s3.upload_fileobj(file, Bucket=self.bucket, Key=self._get_path(key), ExtraArgs=extra_args)