django-private-storage icon indicating copy to clipboard operation
django-private-storage copied to clipboard

Unicode filenames with X-Sendfile + Apache

Open perstar opened this issue 6 years ago • 1 comments

I struggled to get Unicode filenames to work when serving with X-Sendfile via Apache. (Where it worked in the development server.) This was with Python 2 (and Django 1.11). I haven't tested with later versions.

It turned out that when setting a header on a django.http.HttpResponse object to a Unicode string the value instead became a str object which didn't work well when the response object was later used. It works for me by just changing response['X-Sendfile'] = private_file.full_path (which was a unicode) by adding .encode('utf-8') to the end of it in serve in ApacheXSendFileServer in servers.py.

This is the quick fix for me (except it really wasn't quick :-) which might need embellishing to work with different versions and maybe to check what the actual encoding of filenames should be, but hopefully useful as a start or as something to copy for others with the same problem.

perstar avatar Mar 13 '19 21:03 perstar

In Python 3.12.7 and Django 4.2.16 This problem still exists. Your solution works perfectly. The problem is only with Apache.

Elger9 avatar Jan 17 '25 06:01 Elger9