Fix X-Accel-Redirect with non-ASCII names

This commit is contained in:
2026-02-13 22:08:19 +01:00
parent bea1c653f0
commit 53c85e017d

View File

@@ -17,7 +17,7 @@ from django.http import (
) )
from django.views import View from django.views import View
from django.utils.text import slugify as slugify from django.utils.text import slugify as slugify
from django.utils.encoding import smart_str from django.utils.encoding import iri_to_uri, smart_str
from django.utils.decorators import method_decorator from django.utils.decorators import method_decorator
from django.views.decorators.csrf import csrf_exempt from django.views.decorators.csrf import csrf_exempt
@@ -112,7 +112,9 @@ class DownloadFile(View):
if getattr(settings, "USE_X_ACCEL_REDIRECT", False): if getattr(settings, "USE_X_ACCEL_REDIRECT", False):
response = HttpResponse() response = HttpResponse()
response["Content-Type"] = "" response["Content-Type"] = ""
response["X-Accel-Redirect"] = f"/private/{file.name}" response["X-Accel-Redirect"] = iri_to_uri(
f"/private/{file.name}"
)
else: else:
response = FileResponse( response = FileResponse(
open(file.path, "rb"), as_attachment=True open(file.path, "rb"), as_attachment=True