From 5af9b294f56e819a4ec2471a5e59bd556bd180e5 Mon Sep 17 00:00:00 2001 From: Maharshi Patel Date: Tue, 21 Nov 2023 16:34:26 +0530 Subject: [PATCH] fix: honour max file size in upload file In case path is /api/method/upload_file, we should honour the max file size set in system settings and set request max_content_length to that value. --- frappe/app.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/frappe/app.py b/frappe/app.py index c036b65e9c..9ed084742e 100644 --- a/frappe/app.py +++ b/frappe/app.py @@ -179,9 +179,12 @@ def init_request(request): raise frappe.SessionStopped("Session Stopped") else: frappe.connect(set_admin_as_user=False) + if request.path.startswith("/api/method/upload_file"): + from frappe.core.api.file import get_max_file_size - request.max_content_length = cint(frappe.local.conf.get("max_file_size")) or 10 * 1024 * 1024 - + request.max_content_length = get_max_file_size() + else: + request.max_content_length = cint(frappe.local.conf.get("max_file_size")) or 10 * 1024 * 1024 make_form_dict(request) if request.method != "OPTIONS":