Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Encoding of filename #35

Closed
srkunze opened this issue Mar 20, 2020 · 4 comments
Closed

Encoding of filename #35

srkunze opened this issue Mar 20, 2020 · 4 comments

Comments

@srkunze
Copy link

srkunze commented Mar 20, 2020

Hi,

in recents versions, backends.xsendfile.sendfile does not encode the given filename anymore and passes on the Unicode str. That's an issue with special characters like /home/user/test/äüö.pdf.

 def sendfile(request, filename, **kwargs):
    filename = six.text_type(filename)
    if six.PY2:
        filename = filename.encode("utf-8")

    response = HttpResponse()
    response['X-Sendfile'] = filename

    return response

Would it be possible to remove that if-condition?

In case you wonder why we do not pass bytes to sendfile.sendfile in the first place:

sendfile.sendfile uses guess_type(filename), which does not work with bytes.

@srkunze srkunze changed the title Encoding of filename in case of Python3 Encoding of filename Mar 20, 2020
@tidenhub
Copy link

It seems filename = six.text_type(filename) makes trouble cause the latest version works fine:

def sendfile(request, filename, **kwargs):
    filename = str(filename)
    response = HttpResponse()
    response['X-Sendfile'] = filename

@moggers87
Copy link
Owner

moggers87 commented Mar 20, 2020

@srkunze can you tell us which version you're using?

@tidenhub
Copy link

tidenhub commented Mar 20, 2020

@moggers87 We are using 0.4.3, cause we are using it at a Py2 / Py3 System.

@moggers87
Copy link
Owner

I no longer support Python 2.

I suggest making a custom backend with whatever fixes you need and using that until you can migrate to a newer version of django-sendfile2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants