# Write file to Dashboard User Computer

**URL:** https://discourse.nodered.org/t/write-file-to-dashboard-user-computer/52927
**Category:** Dashboard
**Created:** [29 October 2021 06:28 UTC](https://discourse.nodered.org/t/write-file-to-dashboard-user-computer/52927 "2021-10-29T06:28:21Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![Chorum](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/chorum/32/47644_2.png) [@Chorum](https://discourse.nodered.org/u/Chorum)
#### Post date: [29 October 2021 06:28 UTC](https://discourse.nodered.org/t/write-file-to-dashboard-user-computer/52927/1 "2021-10-29T06:28:21Z")

</div>

Hello,

i need to make a backup file but dont have any folder access with Node Red.

So i searched for a solution and came up with the idea to manually download the backup file and upload the backupfile per Dashboard.

I can create the \*.txt if i use a string like = "this is my content", but i cannot manage to use the payload or a global variabel. in an other usecase its a simple {{whatever}}, but its not working here.

thats the part of the flow:

```auto
[{"id":"57c11bc0.c5e24c","type":"http in","z":"a4defdc6.648b4","name":"","url":"/writetest","method":"get","upload":false,"swaggerDoc":"","x":370,"y":880,"wires":[["2bf12a6.07ffe56"]]},{"id":"7e699966.fe154","type":"http response","z":"a4defdc6.648b4","name":"","statusCode":"","headers":{},"x":1010,"y":880,"wires":[]},{"id":"2bf12a6.07ffe56","type":"change","z":"a4defdc6.648b4","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"writetestpaket","tot":"global"}],"action":"","property":"","from":"","to":"","reg":false,"x":570,"y":880,"wires":[["48431356.bd85fc","8fdb2dd6.a7a508"]]},{"id":"48431356.bd85fc","type":"template","z":"a4defdc6.648b4","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"<!DOCTYPE html>\n<html dir=\"ltr\" lang=\"en-US\">\n <head>\n <meta charset=\"utf-8\" />\n <title>Lieferschein-1</title>\n\n<!--<textarea id=\"textbox\">Type something here</textarea> -->\n<button id=\"create\">Create file</button> \n<a download=\"info.txt\" id=\"downloadlink\" style=\"display: none\">Download</a>\n\n\n \n <style>\n </style>\n\n </head>\n \n \n <body>\n <script>\n//Daten aus dem Payload ziehen \n(function(scope) {\n scope.$watch('msg.payload', function(data) {\n update(data);\n });\n})(scope);\n\n//Update der Payloaddaten\nfunction update(data) {\n theScope.send({payload:data});\n}\n\n\n\n (function () {\n var textFile = null,\n makeTextFile = function (text) {\n var data = new Blob([text], {type: 'text/plain'});\n\n // If we are replacing a previously generated file we need to\n // manually revoke the object URL to avoid memory leaks.\n if (textFile !== null) {\n window.URL.revokeObjectURL(textFile);\n }\n\n textFile = window.URL.createObjectURL(data);\n\n return textFile;\n };\n\n\n var create = document.getElementById('create'),\n textbox = document.getElementById('textbox');\n\n create.addEventListener('click', function () {\n var link = document.getElementById('downloadlink');\n link.href = makeTextFile(data);//textbox.value);\n link.style.display = 'block';\n }, false);\n })();\n \n </script>\n </body>\n \n</html>\n","output":"str","x":840,"y":880,"wires":[["7e699966.fe154"]]},{"id":"1a92b9c4.f1de36","type":"ui_button","z":"a4defdc6.648b4","name":"","group":"4d0d29e8.0dce38","order":0,"width":0,"height":0,"passthru":false,"label":"button","tooltip":"","color":"","bgcolor":"","icon":"","payload":"","payloadType":"str","topic":"","x":350,"y":840,"wires":[["4d05080a.cc587"]]},{"id":"a69b16e4.fdcb5","type":"ui_template","z":"a4defdc6.648b4","group":"4d0d29e8.0dce38","name":"","order":0,"width":"6","height":"6","format":"<div ng-bind-html=\"msg.payload | trusted\"></div>","storeOutMessages":true,"fwdInMessages":true,"resendOnRefresh":false,"templateScope":"local","x":840,"y":840,"wires":[[]]},{"id":"4d05080a.cc587","type":"template","z":"a4defdc6.648b4","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"<iframe src=\"/writetest\" height=70px width=100px ></iframe>","x":540,"y":840,"wires":[["a69b16e4.fdcb5"]]},{"id":"1ac5ce2c.511742","type":"comment","z":"a4defdc6.648b4","name":"Datei erzeugen und download","info":"","x":420,"y":800,"wires":[]},{"id":"8fdb2dd6.a7a508","type":"debug","z":"a4defdc6.648b4","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":830,"y":920,"wires":[]},{"id":"4d0d29e8.0dce38","type":"ui_group","name":"Group 1","tab":"17c3cafa.c3d2cd","order":1,"disp":true,"width":6},{"id":"17c3cafa.c3d2cd","type":"ui_tab","z":"","name":"Dateiverwaltung","icon":"dashboard","order":24,"disabled":false,"hidden":false}]

```

the interesting part is in the second template node :

```auto
link.href = makeTextFile(data);

```

i would like to have a payload or a global variable on the "data" position.

I hope somebody can help me with that, i am not good with html..

Dearly  
Chorum

---

<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: [29 October 2021 10:39 UTC](https://discourse.nodered.org/t/write-file-to-dashboard-user-computer/52927/2 "2021-10-29T10:39:03Z")

</div>

This flow might help..

[https://flows.nodered.org/flow/db68bd4934cf46f39e6e453a348bc419](https://flows.nodered.org/flow/db68bd4934cf46f39e6e453a348bc419)

* * *

PS: the template node should NOT have

---

<div class="post-metadata">

### Author: ![Chorum](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/chorum/32/47644_2.png) [@Chorum](https://discourse.nodered.org/u/Chorum)
#### Post date: [29 October 2021 11:26 UTC](https://discourse.nodered.org/t/write-file-to-dashboard-user-computer/52927/3 "2021-10-29T11:26:58Z")

</div>

Thank You!

Seems to be a better solution, for bringing a file to the dashboard user.  
But i think i cant save files to the node red server, but thats not a problem.  
I will work through that and response after that node red is running again.

i dont get "PS: the template node should NOT have" ? 🙂

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [29 October 2021 12:31 UTC](https://discourse.nodered.org/t/write-file-to-dashboard-user-computer/52927/4 "2021-10-29T12:31:59Z")

</div>

> [@Chorum](#):
>
> i think i cant save files to the node red server,

Why can you not save files, or are you using a cloud service that does not have disc storage you can write to

---

<div class="post-metadata">

### Author: ![Chorum](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/chorum/32/47644_2.png) [@Chorum](https://discourse.nodered.org/u/Chorum)
#### Post date: [29 October 2021 12:37 UTC](https://discourse.nodered.org/t/write-file-to-dashboard-user-computer/52927/5 "2021-10-29T12:37:32Z")

</div>

the node red server is set up to not having a folder or drive to write to (not my decision)  
so i try to bring the file to the dashboard user (intern network) as a backup, to load in if globals are gone.

I dont know why but the set of varibales vanish after a short time. the user talked about "some hours".  
i stored them in globals.

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [29 October 2021 12:47 UTC](https://discourse.nodered.org/t/write-file-to-dashboard-user-computer/52927/6 "2021-10-29T12:47:29Z")

</div>

> [@Chorum](#):
>
> I dont know why but the set of varibales vanish after a short time

Possibly node-red restarted.

---

<div class="post-metadata">

### Author: ![Chorum](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/chorum/32/47644_2.png) [@Chorum](https://discourse.nodered.org/u/Chorum)
#### Post date: [29 October 2021 12:58 UTC](https://discourse.nodered.org/t/write-file-to-dashboard-user-computer/52927/7 "2021-10-29T12:58:47Z")

</div>

ok, i asked the administration about that.  
meanwhile i try to bring that backup to live..

---

<div class="post-metadata">

### Author: ![Chorum](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/chorum/32/47644_2.png) [@Chorum](https://discourse.nodered.org/u/Chorum)
#### Post date: [29 October 2021 13:39 UTC](https://discourse.nodered.org/t/write-file-to-dashboard-user-computer/52927/8 "2021-10-29T13:39:13Z")

</div>

is there no way to get a node red variable/value to an html endpoint ?

thats the mustache from the template node:

```auto
<!DOCTYPE html>
<html dir="ltr" lang="en-US">
  <head>
  <meta charset="utf-8" />
  <title>Title</title>
  <h1 id="nurso">{{name}}</h1>

<textarea id="textbox">Type something here</textarea>
<button id="create">Create file</button> 
<a download="info.txt" id="downloadlink" style="display: none">Download</a>

  <style>
  </style>

  </head>
  
  
  <body>
    <script>

    (function () {
    var textFile = null
    makeTextFile = function (text) {
    var data = new Blob([text], {type: 'text/plain'});
    
    // If we are replacing a previously generated file we need to
    // manually revoke the object URL to avoid memory leaks.
    if (textFile !== null) {
      window.URL.revokeObjectURL(textFile);
    }

    textFile = window.URL.createObjectURL(data);

    return textFile;
    };

    var create = document.getElementById('create'),
    textbox = document.getElementById('textbox');
    textbox.value = "4 3 2 1"

    create.addEventListener('click', function () {
    var link = document.getElementById('downloadlink');
    link.href = makeTextFile(textbox.value);//textbox.value);
    link.style.display = 'block';
    }, false);
    })();
    
    </script>
  </body>
  
</html>

```

all i need is my values in that line:

```auto
link.href = makeTextFile(MyNodeRedValue);

```

May be someone has an idea..  
monday i will try to use Steve-Mcl's idea in some way..

---

<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: [28 November 2021 13:40 UTC](https://discourse.nodered.org/t/write-file-to-dashboard-user-computer/52927/9 "2021-11-28T13:40:12Z")

</div>

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