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
11 changes: 11 additions & 0 deletions thumbor_aws/result_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@
"AWS Result Storage",
)

Config.define(
"AWS_RESULT_STORAGE_TAGGING",
False,
"If Result Storage Objects should be tagged with Original Filename",
"AWS Result Storage",
)


class Storage(BaseStorage, S3Client):
def __init__(self, context):
Expand Down Expand Up @@ -138,11 +145,15 @@ async def put(self, image_bytes: bytes) -> str:
file_abspath = normalize_path(self.context, self.prefix, self.context.request.url)
logger.debug("[RESULT_STORAGE] putting at %s", file_abspath)
content_type = BaseEngine.get_mimetype(image_bytes)
tags = None
if self.context.config.AWS_RESULT_STORAGE_TAGGING:
tags = {"AWS_RESULT_STORAGE_ORIGINAL": self.context.request.image_url}
response = await self.upload(
file_abspath,
image_bytes,
content_type,
self.context.config.AWS_DEFAULT_LOCATION,
tags=tags,
)
logger.info(
"[RESULT_STORAGE] Image uploaded successfully to %s", file_abspath
Expand Down
3 changes: 3 additions & 0 deletions thumbor_aws/s3_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ async def upload(
data: bytes,
content_type,
default_location,
tags: dict[str, str] | None = None,
) -> str:
"""Uploads a File to S3"""

Expand All @@ -127,6 +128,8 @@ async def upload(
}
if self.file_acl is not None:
settings["ACL"] = self.file_acl
if tags is not None:
settings["Tagging"] = "&".join(f"{key}={value}" for key, value in tags.items())

response = await client.put_object(**settings)
except Exception as error:
Expand Down