I wanted to serve protected contents in Django, so I tried to set xsendfile in both Django and Apache. It works for ASCII file names, but when I tried with non-ASCII file name the Apache server responds with 404. What’s going on here?
Django:
def media_xsendfile_pdf(request):
file = Media.objects.last()
response = HttpResponse()
response['Content-Type'] = 'application/pdf'
response['X-Sendfile'] = smart_str(f"{settings.BASE_DIR}{file.file.url}")
return response
Apache:
AllowEncodedSlashes On
XSendFile On
XsendFilePath /path-to-the-protected-resource