Преглед на файлове

fix: support non-ascii charactors in filename of the tool files (#19228)

tags/1.4.0
Bowen Liang преди 5 месеца
родител
ревизия
22f5af9987
No account linked to committer's email address
променени са 2 файла, в които са добавени 6 реда и са изтрити 2 реда
  1. 4
    1
      api/controllers/files/tool_files.py
  2. 2
    1
      api/core/tools/tool_file_manager.py

+ 4
- 1
api/controllers/files/tool_files.py Целия файл

@@ -1,3 +1,5 @@
from urllib.parse import quote

from flask import Response
from flask_restful import Resource, reqparse # type: ignore
from werkzeug.exceptions import Forbidden, NotFound
@@ -46,7 +48,8 @@ class ToolFilePreviewApi(Resource):
if tool_file.size > 0:
response.headers["Content-Length"] = str(tool_file.size)
if args["as_attachment"]:
response.headers["Content-Disposition"] = f"attachment; filename={tool_file.name}"
encoded_filename = quote(tool_file.name)
response.headers["Content-Disposition"] = f"attachment; filename*=UTF-8''{encoded_filename}"

return response


+ 2
- 1
api/core/tools/tool_file_manager.py Целия файл

@@ -4,6 +4,7 @@ import hmac
import logging
import os
import time
from collections.abc import Generator
from mimetypes import guess_extension, guess_type
from typing import Optional, Union
from uuid import uuid4
@@ -215,7 +216,7 @@ class ToolFileManager:

return blob, tool_file.mimetype

def get_file_generator_by_tool_file_id(self, tool_file_id: str):
def get_file_generator_by_tool_file_id(self, tool_file_id: str) -> tuple[Optional[Generator], Optional[ToolFile]]:
"""
get file binary


Loading…
Отказ
Запис