Write file to Dashboard User Computer


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:

[{"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 :

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..


This flow might help..


PS: the template node should NOT have

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" ? :slight_smile:

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

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.

Possibly node-red restarted.

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

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

thats the mustache from the template node:

<!DOCTYPE html>
<html dir="ltr" lang="en-US">
  <meta charset="utf-8" />
  <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>



    (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) {

    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);

all i need is my values in that line:

link.href = makeTextFile(MyNodeRedValue);

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

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