fix: FileOption return already saved and hashed filepath

This commit is contained in:
axolotle 2023-11-25 21:37:29 +01:00
parent 321aea4171
commit e5a593a4bb

View file

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