I am trying to download a file stored on the server using the following:
In PY:
@frappe.whitelist()
def download_test():
frappe.local.response.filename = "test.txt"
with open("/tmp/test.txt", "rb") as fileobj:
filedata = fileobj.read()
frappe.local.response.filecontent = filedata
frappe.local.response.type = "download"
In JS:
frappe.call({
method: "frappe.mypyfile.download_test",
args: {
},
callback: function(r) {
}
});
I get a “Uncaught SyntaxError: Unexpected token” error.
But if I run:
window.open("/api/method/frappe.mypyfile.download_test");
It works…
I’m quite stumped here, does anyone know why frappe.local.response does not work on an active window and requires it to be launched via a new window?