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

**URL:** <https://discourse.nodered.org/t/get-a-file-and-then-download-it-through-the-web-browser/74746>\
**Category:** General\
**Created:** [5 February 2023 19:04 UTC](https://discourse.nodered.org/t/get-a-file-and-then-download-it-through-the-web-browser/74746 "2023-02-05T19:04:30Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![network\_potato](https://avatars.discourse-cdn.com/v4/letter/n/59ef9b/32.png) [@network\_potato](https://discourse.nodered.org/u/network_potato)\
**Post date:** [5 February 2023 19:04 UTC](https://discourse.nodered.org/t/get-a-file-and-then-download-it-through-the-web-browser/74746/1 "2023-02-05T19:04:30Z")

</div>

I have some HTML with a link:

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

```

Where [example.com](http://example.com) is my Node-RED instance with a `/get-pdf` http endpoint:

 ![Skjermbilde 2023-02-05 kl. 20.02.14](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/7/d70d8482e7d960181537d90a1f1d3a343857ac08.png)

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?

---

<div class="post-metadata">

**Author:** ![michaelblight](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/michaelblight/32/445_2.png) [@michaelblight](https://discourse.nodered.org/u/michaelblight)\
**Post date:** [6 February 2023 04:10 UTC](https://discourse.nodered.org/t/get-a-file-and-then-download-it-through-the-web-browser/74746/2 "2023-02-06T04:10:47Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![network\_potato](https://avatars.discourse-cdn.com/v4/letter/n/59ef9b/32.png) [@network\_potato](https://discourse.nodered.org/u/network_potato)\
**Post date:** [6 February 2023 07:05 UTC](https://discourse.nodered.org/t/get-a-file-and-then-download-it-through-the-web-browser/74746/3 "2023-02-06T07:05:30Z")

</div>

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

![get-pdf](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/4/c4a8458211482409924272c1d67184eee3524266.png)

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

Is this correct programming of the reponse node?

 ![http-response](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/f/bfd34a92a2f0804030c71afdf606abd97b084f88.png)

The flow looks like this:

 ![flow](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/7/f7748ce527ea9322f23cf83ade67fbba7dc46282.png)

The request node should be set to this, right?  
 ![req](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/8/a889e605e80d08e2cafe6ed10427c4b9d7cb8106.png)

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [6 February 2023 07:12 UTC](https://discourse.nodered.org/t/get-a-file-and-then-download-it-through-the-web-browser/74746/4 "2023-02-06T07:12:15Z")

</div>

> [@network\_potato](#):
>
> Is this correct programming of the reponse node?
> 
> ![http-response](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/f/bfd34a92a2f0804030c71afdf606abd97b084f88.png)

Don't include quotes in string fields

---

<div class="post-metadata">

**Author:** ![network\_potato](https://avatars.discourse-cdn.com/v4/letter/n/59ef9b/32.png) [@network\_potato](https://discourse.nodered.org/u/network_potato)\
**Post date:** [6 February 2023 07:23 UTC](https://discourse.nodered.org/t/get-a-file-and-then-download-it-through-the-web-browser/74746/5 "2023-02-06T07:23:56Z")

</div>

Still the same result without the quotes 😕

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [6 February 2023 07:40 UTC](https://discourse.nodered.org/t/get-a-file-and-then-download-it-through-the-web-browser/74746/6 "2023-02-06T07:40:15Z")

</div>

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"`

---

<div class="post-metadata">

**Author:** ![network\_potato](https://avatars.discourse-cdn.com/v4/letter/n/59ef9b/32.png) [@network\_potato](https://discourse.nodered.org/u/network_potato)\
**Post date:** [6 February 2023 11:50 UTC](https://discourse.nodered.org/t/get-a-file-and-then-download-it-through-the-web-browser/74746/7 "2023-02-06T11:50:15Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [20 February 2023 11:50 UTC](https://discourse.nodered.org/t/get-a-file-and-then-download-it-through-the-web-browser/74746/8 "2023-02-20T11:50:53Z")

</div>

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