/GET a file and then download it through the web browser?

I have some HTML with a link:

<a href="https://example.com/get-pdf">Download PDF</a>

Where example.com is my Node-RED instance with a /get-pdf http endpoint:

This flow then GETs the file through another http request (because the file is behind an API that needs a bearer token).

My question is: how do I return this fille so that the person who clicked the link gets the file as a normal file download in their browser?

You can set the content-type header in the HTTP response node to "application/octet-stream" to 'force' a download. If you set it to "application/pdf" I suspect Chrome (for example) might use its own reader rather than downloading it. Not tested though.

Unfortunately that didn't work. The result was this "file":

get-pdf

Same result with both application/octet-stream and application/pdf.

Is this correct programming of the reponse node?

The flow looks like this:

The request node should be set to this, right?
req

Don't include quotes in string fields

Still the same result without the quotes :confused:

Have you specified a file name anywhere?
If you are ok with a fixed/static file name, just add another header

name: Content-Disposition
value: attachment; filename="file.pdf"

Thanks! That worked perfectly.

Well, it would be great to be able to specify the filename.

I tried using a {{{variable}}} as part of the filename but that didn't work.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.