fix: re-upload with different name maintains original name (#37313)

* fix: use actual file name for private files

* fix: add id to download button

* fix: add fid in view file too

---------

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
This commit is contained in:
Suraj Shetty 2026-02-21 00:58:42 +05:30 committed by GitHub
commit 6556c13ba5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 8 additions and 6 deletions

View file

@ -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");
}

View file

@ -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