Downloading File using frappe.local.response

I am trying to download a file stored on the server using the following:

In PY:

def download_test():
	frappe.local.response.filename = "test.txt"
	with open("/tmp/test.txt", "rb") as fileobj:
		filedata =
	frappe.local.response.filecontent = filedata
	frappe.local.response.type = "download"

In JS:{
	method: "frappe.mypyfile.download_test",
	args: {

	callback: function(r) {

I get a “Uncaught SyntaxError: Unexpected token” error.

But if I run:"/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?

1 Like

@bohlian expect a JSON object! is the nice approach!