s3 allow online preview instead of forced download

This commit is contained in:
msramalho
2022-07-14 18:16:06 +02:00
parent d701141c1b
commit 6d8be4c07f

View File

@@ -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)