Skip to content

Commit

Permalink
Merge branch 'main' of github.com:aminalaee/fastapi-storages into upd…
Browse files Browse the repository at this point in the history
…ate-dependencies
  • Loading branch information
aminalaee committed Feb 15, 2024
2 parents 0a001d5 + ebd48fd commit 14c19e9
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions fastapi_storages/s3.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import mimetypes
import os
from pathlib import Path
from typing import BinaryIO
Expand All @@ -18,6 +19,8 @@ class S3Storage(BaseStorage):
Requires `boto3` to be installed.
"""

default_content_type = "application/octet-stream"

AWS_ACCESS_KEY_ID = os.environ.get("AWS_ACCESS_KEY_ID", "")
"""AWS access key ID. Either set here or as an environment variable."""

Expand Down Expand Up @@ -110,8 +113,12 @@ def write(self, file: BinaryIO, name: str) -> str:

file.seek(0, 0)
key = self.get_name(name)

self._bucket.upload_fileobj(file, key, ExtraArgs={"ACL": self.AWS_DEFAULT_ACL})
content_type, _ = mimetypes.guess_type(key)
params = {
"ACL": self.AWS_DEFAULT_ACL,
"ContentType": content_type or self.default_content_type,
}
self._bucket.upload_fileobj(file, key, ExtraArgs=params)
return key

def generate_new_filename(self, filename: str) -> str:
Expand Down

0 comments on commit 14c19e9

Please sign in to comment.