From 17622c1fbf179a744a9b368c1605278bec25ec4a Mon Sep 17 00:00:00 2001 From: Jan Broer Date: Sat, 26 Mar 2016 17:17:11 +0100 Subject: [PATCH] Fix download error when book title contains non-latin characters (e.g. Chinese) --- cps/web.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/cps/web.py b/cps/web.py index 9eccb581..c057eb3d 100755 --- a/cps/web.py +++ b/cps/web.py @@ -212,7 +212,14 @@ def get_opds_download_link(book_id, format): file_name = author+'-'+file_name file_name = helper.get_valid_filename(file_name) response = make_response(send_from_directory(os.path.join(config.DB_ROOT, book.path), data.name + "." +format)) - response.headers["Content-Disposition"] = "attachment; filename=%s.%s" % (file_name, format) + #response.headers["Content-Disposition"] = "attachment; filename=%s.%s" % (data.name, format) + response.headers["Content-Disposition"] = \ + "attachment; " \ + "filename={utf_filename}.{suffix};" \ + "filename*=UTF-8''{utf_filename}.{suffix}".format( + utf_filename=file_name.encode('utf-8'), + suffix=format + ) return response @app.route("/", defaults={'page': 1}) @@ -363,7 +370,14 @@ def get_download_link(book_id, format): file_name = author+'-'+file_name file_name = helper.get_valid_filename(file_name) response = make_response(send_from_directory(os.path.join(config.DB_ROOT, book.path), data.name + "." +format)) - response.headers["Content-Disposition"] = "attachment; filename=%s.%s" % (file_name, format) + #response.headers["Content-Disposition"] = "attachment; filename=%s.%s" % (file_name, format) + response.headers["Content-Disposition"] = \ + "attachment; " \ + "filename={utf_filename}.{suffix};" \ + "filename*=UTF-8''{utf_filename}.{suffix}".format( + utf_filename=file_name.encode('utf-8'), + suffix=format + ) return response @app.route('/register', methods = ['GET', 'POST'])