django-sendfile icon indicating copy to clipboard operation
django-sendfile copied to clipboard

Problem with unicode characters

Open pando85 opened this issue 9 years ago • 10 comments

When I try to set up to sendfile with spanish characters (like: á, é, í, ó, ú...) using nginx backend, the link of sendfile response its: 404 not found.

pando85 avatar Jan 06 '16 12:01 pando85

I was trying Bulgarian characters (like: А, Б, В, Г, Д....) and everything works with Nginx backned under Python 3.

Can you investigate where exactly the things get broken.

vstoykov avatar Feb 12 '16 08:02 vstoykov

I suspect it's more to do with how the default encoding on the server is setup etc.

lilspikey avatar Feb 12 '16 09:02 lilspikey

It could be related with server encoding, I don't remember right now and I can't tested, sorry.

pando85 avatar Feb 12 '16 13:02 pando85

The problem is that the URL that's handed to nginx via the X-Accel-Redirect header isn't quoted. If you use urllib.parse.quote() on the URL there're no problem. I was going to fix this and add general Python 3 support next week. Is there a chance a PR with these changes will get reviewed and merged?

Proper-Job avatar Jun 22 '16 13:06 Proper-Job

Possibly. I started a new job 3 months ago and it's been pretty intense...

lilspikey avatar Jun 23 '16 05:06 lilspikey

@lilspikey that's not much to go on. What would it take for you to review a PR?
The main thing that we ran into (using Python3) is the quote issue. What if I made a PR for that and updated the tests accordingly. Would you be able to review that within the month of July?

Proper-Job avatar Jun 23 '16 07:06 Proper-Job

I have a suggestion for generating the value for X-Accel-Redirect. Why not simply use Django's FileSystemStorage for generating the url and also validating the path to the file.

We can have a sendfile_storage which will be:

 sendfile_storage = FileSystemStorage(SENDFILE_ROOT, SENDFILE_URL)

And then calculating the internal URL will be just:

internal_url = sendfile_storage.url(filename)

I think that this will solve the problem with the encoding.

For more info https://docs.djangoproject.com/en/1.9/ref/files/storage/#the-filesystemstorage-class

vstoykov avatar Jun 23 '16 11:06 vstoykov

@Proper-Job hopefully I could review it in July. If it's just the quoting, then it shouldn't be a large change, so should manage it. New job doesn't involve Django at all, so this would purely be done in personal time.

@vstoykov that looks like it might work, but for the sake of a small change it might be easier to just go with adding quoting for now.

lilspikey avatar Jun 23 '16 20:06 lilspikey

I created a PR for this issue. I successfully tested it on nginx. https://github.com/johnsensible/django-sendfile/pull/54

Proper-Job avatar Jun 30 '16 10:06 Proper-Job

Note that escaped URIs breaks support for Nginx versions older than 1.5.9 which isn't expecting them in the X-Accel-Redirect header.

I personally think this is fine seeming as it's either not-supporting a 3-year-old release of Nginx or not-supporting unicode file names. But I'm leaving this as a note for anyone noticing the breakage when upgrading sendfile.

willstott101 avatar Nov 22 '16 14:11 willstott101