Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ coverage.xml
.pytest_cache/
.mypy_cache/
.ruff_cache/
.idea/*
31 changes: 24 additions & 7 deletions fastapi_storages/s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ class S3Storage(BaseStorage):
"""Optional ACL set on the object like `public-read`.
By default file will be private."""

AWS_SIGNATURE_VERSIONS = "s3v4"
"""Optional signature versions.
Note that the default version is Signature Version 4.
If you’re using a presigned URL with an expiry of greater than 7 days,
you should specify Signature Version 2."""

AWS_QUERYSTRING_AUTH = False
"""Indicate if query parameter authentication should be used in URLs."""

Expand All @@ -54,13 +60,24 @@ def __init__(self) -> None:

self._http_scheme = "https" if self.AWS_S3_USE_SSL else "http"
self._url = f"{self._http_scheme}://{self.AWS_S3_ENDPOINT_URL}"
self._s3 = boto3.client(
"s3",
endpoint_url=self._url,
use_ssl=self.AWS_S3_USE_SSL,
aws_access_key_id=self.AWS_ACCESS_KEY_ID,
aws_secret_access_key=self.AWS_SECRET_ACCESS_KEY,
)

if self.AWS_SIGNATURE_VERSIONS == "s3":
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is this not s3v4?

self._s3 = boto3.client(
"s3",
endpoint_url=self._url,
use_ssl=self.AWS_S3_USE_SSL,
signature_version=self.AWS_SIGNATURE_VERSIONS,
aws_access_key_id=self.AWS_ACCESS_KEY_ID,
aws_secret_access_key=self.AWS_SECRET_ACCESS_KEY,
)
else:
self._s3 = boto3.client(
"s3",
endpoint_url=self._url,
use_ssl=self.AWS_S3_USE_SSL,
aws_access_key_id=self.AWS_ACCESS_KEY_ID,
aws_secret_access_key=self.AWS_SECRET_ACCESS_KEY,
)

def get_name(self, name: str) -> str:
"""
Expand Down
Loading