Serving mixed filenames with send_from_directory() errors out.

General support questions
Post Reply
NikosThess
Posts: 19
Joined: 2018/05/10 20:36:20

Serving mixed filenames with send_from_directory() errors out.

Post by NikosThess » 2018/09/20 03:50:42

In an html form i have a user selecting a filename, which then i tried to send to his browser. Here is the code:

Code: Select all

    filename = request.form.get('filename')
    filepath = '/home/nikos/wsgi/static/files/'

    return send_from_directory(filepath, filename)
If the filename selected is in english characters it gets send the user, but, if it contained a mix of english + greek chars it gives a `bad request` i tried to encode `filename.encode("utf-8") but then NO files are being served.

[Moderator: Moved from the "Website" section as that is for reporting problems with the CentOS website, not yours]

hunter86_bg
Posts: 1357
Joined: 2015/02/17 15:14:33
Location: Bulgaria
Contact:

Re: Serving mixed filenames with send_from_directory() errors out.

Post by hunter86_bg » 2018/09/23 04:55:25

Have you tried to convert the name to utf-8 and check what is the output before trying to access the file?

NikosThess
Posts: 19
Joined: 2018/05/10 20:36:20

Re: Serving mixed filenames with send_from_directory() errors out.

Post by NikosThess » 2018/09/23 05:55:06

Yes i did, but i still receive the exact same error.

Post Reply