diff --git a/frappe/core/doctype/file/file.js b/frappe/core/doctype/file/file.js index c8122ee0af..f3f1380855 100644 --- a/frappe/core/doctype/file/file.js +++ b/frappe/core/doctype/file/file.js @@ -3,7 +3,9 @@ frappe.ui.form.on("File", { if (frm.doc.file_url) { frm.add_custom_button(__("View File"), () => { if (!frappe.utils.is_url(frm.doc.file_url)) { - window.open(window.location.origin + frm.doc.file_url); + window.open( + window.location.origin + frm.doc.file_url + "?fid=" + frm.doc.name + ); } else { window.open(frm.doc.file_url); } @@ -90,7 +92,7 @@ frappe.ui.form.on("File", { }, download: function (frm) { - let file_url = frm.doc.file_url; + let file_url = frm.doc.file_url + "?fid=" + frm.doc.name; if (frm.doc.file_name) { file_url = file_url.replace(/#/g, "%23"); } diff --git a/frappe/utils/response.py b/frappe/utils/response.py index ba4a6f7979..5fdd459c95 100644 --- a/frappe/utils/response.py +++ b/frappe/utils/response.py @@ -295,15 +295,15 @@ def download_private_file(path: str) -> Response: raise Forbidden(_("You don't have permission to access this file")) make_access_log(doctype="File", document=file.name, file_type=os.path.splitext(path)[-1][1:]) - return send_private_file(path.split("/private", 1)[1]) + return send_private_file(path.split("/private", 1)[1], filename=file.file_name) FORCE_DOWNLOAD_EXTENSIONS = (".svg", ".html", ".htm", ".xml") -def send_private_file(path: str) -> Response: +def send_private_file(path: str, filename: str | None = None) -> Response: path = os.path.join(frappe.local.conf.get("private_path", "private"), path.strip("/")) - filename = os.path.basename(path) + filename = filename or os.path.basename(path) extension = os.path.splitext(path)[1] as_attachment = extension.lower() in FORCE_DOWNLOAD_EXTENSIONS @@ -329,7 +329,7 @@ def send_private_file(path: str) -> Response: environ=frappe.local.request.environ, conditional=True, as_attachment=as_attachment, - download_name=filename if as_attachment else None, + download_name=filename, ) return response