fix: 500 error when downloading projects with non-ASCII characters (ex. Cyrillic) names (#8483)
* fix: encode Cyrillic filenames in Content-Disposition header * [autofix.ci] apply automated fixes --------- Co-authored-by: Ilia Krupin <ilia.krupin@tedo.ru> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: Gabriel Luiz Freitas Almeida <gabriel@langflow.org>
This commit is contained in:
parent
15f0c7040b
commit
1236643711
1 changed files with 6 additions and 2 deletions
|
|
@ -3,6 +3,7 @@ import json
|
|||
import zipfile
|
||||
from datetime import datetime, timezone
|
||||
from typing import Annotated
|
||||
from urllib.parse import quote
|
||||
from uuid import UUID
|
||||
|
||||
import orjson
|
||||
|
|
@ -292,17 +293,20 @@ async def download_file(
|
|||
with zipfile.ZipFile(zip_stream, "w") as zip_file:
|
||||
for flow in flows_without_api_keys:
|
||||
flow_json = json.dumps(jsonable_encoder(flow))
|
||||
zip_file.writestr(f"{flow['name']}.json", flow_json)
|
||||
zip_file.writestr(f"{flow['name']}.json", flow_json.encode("utf-8"))
|
||||
|
||||
zip_stream.seek(0)
|
||||
|
||||
current_time = datetime.now(tz=timezone.utc).astimezone().strftime("%Y%m%d_%H%M%S")
|
||||
filename = f"{current_time}_{project.name}_flows.zip"
|
||||
|
||||
# URL encode filename handle non-ASCII (ex. Cyrillic)
|
||||
encoded_filename = quote(filename)
|
||||
|
||||
return StreamingResponse(
|
||||
zip_stream,
|
||||
media_type="application/x-zip-compressed",
|
||||
headers={"Content-Disposition": f"attachment; filename={filename}"},
|
||||
headers={"Content-Disposition": f"attachment; filename*=UTF-8''{encoded_filename}"},
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue