Download apps/documents/api/download_response_factory.py from jun2024/fc: direct link, hf CLI and curl.
- Browser
- Download file 595 Bytes
-
https://huggingface.co/spaces/jun2024/fc/resolve/main/apps/documents/api/download_response_factory.py
- Command line
-
hf download hf://spaces/jun2024/fc/apps/documents/api/download_response_factory.py
-
curl -L -o download_response_factory.py https://huggingface.co/spaces/jun2024/fc/resolve/main/apps/documents/api/download_response_factory.py
595 Bytes
| """API endpoints.""" | |
| from urllib.parse import quote | |
| from django.http import HttpResponse | |
| def build_download_response(*, content: bytes, filename: str, content_type: str) -> HttpResponse: | |
| response = HttpResponse(content, content_type=content_type) | |
| # filename="..." 使用百分号编码(ASCII 安全,避免 Django MIME 编码破坏正则匹配) | |
| # filename*=UTF-8'' 同样使用百分号编码(RFC 5987,浏览器会自动解码) | |
| response["Content-Disposition"] = f"attachment; filename=\"{quote(filename)}\"; filename*=UTF-8''{quote(filename)}" | |
| return response | |