hello guys,
my "program" creates a new file with date and time in its name (the file contains measured data, not important for my problem). Now I want to download the newest file via a download button. With following "tutorial" I can download the newest file which is fine so far (see reply post for link):
the problem I have now is that the downloaded file contains the correct (newest) data, but the filename is static. It doesn't have the date and time in it as original, instead its name is defined in the template node (In the tutorial it's "log.log"). In my flow (see code below), I wanted to change the download link to flow.filename_download (I defined this variable in another node), but instead of taking the value stored in flow.filename_download, it just saves the file as "flow.filename_download".
So when I make a measure which creates a new file, download this file, make a new measure and download the new file, both files have the "same" name (only difference is the browser creates automatically an (1) after the name).
In my node I worked with <button onclick...>, but the same happens with <a href..>
[{"id":"84f44064.d1cf4","type":"tab","label":"Flow 5","disabled":false,"info":""},{"id":"615a6ffd.f28aa","type":"function","z":"84f44064.d1cf4","name":"Set base path","func":"var basePath = \"/home/pi/Documents/S0_data/\";\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":"","libs":[],"x":300,"y":100,"wires":[["3660340e.5439fc"],["db65d67d.bbb078"]]},{"id":"db65d67d.bbb078","type":"http response","z":"84f44064.d1cf4","name":"","statusCode":"","headers":{},"x":710,"y":200,"wires":[]},{"id":"66b84db9.a899d4","type":"file in","z":"84f44064.d1cf4","name":"","filename":"","format":"","chunk":false,"sendError":false,"encoding":"none","x":710,"y":60,"wires":[["db65d67d.bbb078"]]},{"id":"98bbe24b.33931","type":"catch","z":"84f44064.d1cf4","name":"","scope":null,"uncaught":false,"x":120,"y":220,"wires":[["4e017f6.c2ae28","7b5c3dce.93b074"]]},{"id":"4e017f6.c2ae28","type":"function","z":"84f44064.d1cf4","name":"Set 404","func":"msg.payload = msg.error;\nmsg.statusCode = 404;//resource not found\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":480,"y":240,"wires":[["db65d67d.bbb078"]]},{"id":"7b5c3dce.93b074","type":"debug","z":"84f44064.d1cf4","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":130,"y":280,"wires":[]},{"id":"8269edfc.29861","type":"ui_template","z":"84f44064.d1cf4","group":"48c804f9.20970c","name":"Download Button","order":0,"width":0,"height":0,"format":"<button onclick=\"document.location='/files/flow.filename_download'\">Download Daten</button>\n","storeOutMessages":true,"fwdInMessages":true,"resendOnRefresh":false,"templateScope":"local","x":370,"y":320,"wires":[[]]},{"id":"b2cc8c98.3f73a","type":"http in","z":"84f44064.d1cf4","name":"","url":"/files/:fn","method":"get","upload":false,"swaggerDoc":"","x":130,"y":100,"wires":[["615a6ffd.f28aa"]]},{"id":"3660340e.5439fc","type":"change","z":"84f44064.d1cf4","name":"","rules":[{"t":"set","p":"filename","pt":"msg","to":"filename_counter","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":510,"y":60,"wires":[["66b84db9.a899d4"]]},{"id":"48c804f9.20970c","type":"ui_group","name":"allgemein","tab":"8ec7137.b39f5f","order":5,"disp":false,"width":"6","collapse":false},{"id":"8ec7137.b39f5f","type":"ui_tab","name":"MenĂĽ","icon":"more_vert","order":2,"disabled":false,"hidden":false}]