From 8bcd4798312eba2b9dcb37fadda2627dd1026b9c Mon Sep 17 00:00:00 2001 From: Manas Solanki Date: Fri, 10 Feb 2017 17:13:01 +0530 Subject: [PATCH] Add binary mime type in response.py --- frappe/utils/response.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/frappe/utils/response.py b/frappe/utils/response.py index e5de1feea9..0417a38551 100644 --- a/frappe/utils/response.py +++ b/frappe/utils/response.py @@ -36,7 +36,8 @@ def build_response(response_type=None): 'download': as_raw, 'json': as_json, 'page': as_page, - 'redirect': redirect + 'redirect': redirect, + 'binary': as_binary } return response_type_map[frappe.response.get('type') or response_type]() @@ -68,6 +69,13 @@ def as_json(): response.data = json.dumps(frappe.local.response, default=json_handler, separators=(',',':')) return response +def as_binary(): + response = Response() + response.mimetype = 'application/octet-stream' + response.headers[b"Content-Disposition"] = ("filename=\"%s\"" % frappe.response['filename'].replace(' ', '_')).encode("utf-8") + response.data = frappe.response['filecontent'] + return response + def make_logs(response = None): """make strings for msgprint and errprint""" if not response: