From 5af9b294f56e819a4ec2471a5e59bd556bd180e5 Mon Sep 17 00:00:00 2001 From: Maharshi Patel Date: Tue, 21 Nov 2023 16:34:26 +0530 Subject: [PATCH 1/2] 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": From 28d05c41c3be7b0a524865036348d5508a5f84ba Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Wed, 22 Nov 2023 10:52:35 +0530 Subject: [PATCH 2/2] fix: correct max file size in boot --- frappe/app.py | 2 +- frappe/boot.py | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/frappe/app.py b/frappe/app.py index 9ed084742e..0284968113 100644 --- a/frappe/app.py +++ b/frappe/app.py @@ -184,7 +184,7 @@ def init_request(request): 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 + request.max_content_length = cint(frappe.local.conf.get("max_file_size")) or 25 * 1024 * 1024 make_form_dict(request) if request.method != "OPTIONS": diff --git a/frappe/boot.py b/frappe/boot.py index c36927637a..2ce950a55a 100644 --- a/frappe/boot.py +++ b/frappe/boot.py @@ -122,12 +122,12 @@ def get_letter_heads(): def load_conf_settings(bootinfo): - from frappe import conf + from frappe.core.api.file import get_max_file_size - bootinfo.max_file_size = conf.get("max_file_size") or 10485760 + bootinfo.max_file_size = get_max_file_size() for key in ("developer_mode", "socketio_port", "file_watcher_port"): - if key in conf: - bootinfo[key] = conf.get(key) + if key in frappe.conf: + bootinfo[key] = frappe.conf.get(key) def load_desktop_data(bootinfo):