From e5a593a4bb147d27d8969815ec37984b75b032a1 Mon Sep 17 00:00:00 2001 From: axolotle Date: Sat, 25 Nov 2023 21:37:29 +0100 Subject: [PATCH] fix: FileOption return already saved and hashed filepath --- src/utils/form.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/utils/form.py b/src/utils/form.py index 02ce8cd8f..5db9afcc2 100644 --- a/src/utils/form.py +++ b/src/utils/form.py @@ -1363,9 +1363,19 @@ class FileOption(BaseInputOption): if not value: return "" - content, ext = cls._base_value_post_validator(value, field) bind = field.field_info.extra["bind"] + # to avoid "filename too long" with b64 content + if len(value.encode("utf-8")) < 255: + # Check if value is an already hashed and saved filepath + path = Path(value) + if path.exists() and value == bind.format( + filename=path.stem, ext=path.suffix + ): + return value + + content, ext = cls._base_value_post_validator(value, field) + m = hashlib.sha256() m.update(content) sha256sum = m.hexdigest()