I want to export a file by clicking a button. There are the flows I'm using for:
[{"id":"7adc8e2c.3a56d","type":"function","z":"339f2e0a.80f992","name":"Base path","func":"//var basePath = \"/home/pi/Documents/S0_data/\";\nvar basePath = \"/var/snap/node-red/675/\";\nvar filename = msg.req.params.fn;\n\n\nif(filename.includes(\"..\\\\\")){\n msg.payload = \"Illegal file path\";\n msg.statusCode = 405;//not allowed\n return [null, msg];//fire output 2\n} else if(filename.includes(\"../\")){\n msg.payload = \"Illegal file path\";\n msg.statusCode = 405;//not allowed\n return [null, msg];//fire output 2\n} \n//TODO: add more checks\n\nmsg.filename = basePath + filename;\nreturn [msg, null];//fire output 1\n\n\n","outputs":2,"noerr":0,"initialize":"","finalize":"","x":240,"y":140,"wires":[["a1d36f5f.bfd8d"],["74bf307e.adb05"]]},{"id":"74bf307e.adb05","type":"http response","z":"339f2e0a.80f992","name":"","statusCode":"","headers":{},"x":410,"y":200,"wires":[]},{"id":"a1d36f5f.bfd8d","type":"file in","z":"339f2e0a.80f992","name":"","filename":"","format":"","chunk":false,"sendError":false,"encoding":"none","x":410,"y":140,"wires":[["74bf307e.adb05"]]},{"id":"ea09d67e.e1bda8","type":"catch","z":"339f2e0a.80f992","name":"","scope":null,"uncaught":false,"x":100,"y":200,"wires":[["68386e48.5dacf"]]},{"id":"68386e48.5dacf","type":"function","z":"339f2e0a.80f992","name":"Set 404","func":"msg.payload = msg.error;\nmsg.statusCode = 404;//resource not found\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":240,"y":200,"wires":[["74bf307e.adb05"]]},{"id":"3c05ab7d.2c9ed4","type":"ui_template","z":"339f2e0a.80f992","group":"2b825e99.b695e2","name":"Download Button","order":9,"width":"2","height":"1","format":"<button style= \"background-color:#097479; border-color:#097479; color:white; font-size: 13px; padding: 10px\" button onclick=\"document.location='/var/snap/node-red/675/export.csv'\"><b>Download</b></button>\n\n","storeOutMessages":true,"fwdInMessages":true,"resendOnRefresh":false,"templateScope":"local","className":"","x":130,"y":80,"wires":[[]]},{"id":"46bab025.c8036","type":"http in","z":"339f2e0a.80f992","name":"[Get] path","url":"/var/snap/node-red/675/:fn","method":"get","upload":false,"swaggerDoc":"","x":100,"y":140,"wires":[["7adc8e2c.3a56d"]]},{"id":"2b825e99.b695e2","type":"ui_group","name":"Buttons","tab":"20a844b0.75e7fc","order":8,"disp":false,"width":"5","collapse":false},{"id":"20a844b0.75e7fc","type":"ui_tab","name":"S314","icon":"fa-2x fa-bar-chart","order":3,"disabled":false,"hidden":false}]
The code is working fine but I want to use an ui-button instead the template button, is it possible?
Thanks in advance.