Dowloading a CSV-file via dashboard button

#1

Hello

I'm pretty new to Node-red.
I've already made a program that writes a CSV-file.
My aim with this project is to display a link to download the file via the dashboard so the end user can download it.
I've been searching and I think I found a solution but I'm not quiet able to make it work, can someone help me?

This is my flow.

[{"id":"dca47443.30a3f8","type":"inject","z":"9859d967.3b9e48","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":"","x":420,"y":280,"wires":[["751671a3.91b4e8"]]},{"id":"751671a3.91b4e8","type":"function","z":"9859d967.3b9e48","name":"","func":"msg.payload = {};\nmsg.payload = {\"col1\": 1, \"col2\": 2};\nreturn msg;","outputs":1,"noerr":0,"x":570,"y":280,"wires":[["30eb5d75.48c2c2"]]},{"id":"f0b672e0.bf6da8","type":"file","z":"9859d967.3b9e48","name":"TEST.CSV","filename":"~/TEST.CSV","appendNewline":true,"createDir":true,"overwriteFile":"true","x":870,"y":280,"wires":[[]]},{"id":"30eb5d75.48c2c2","type":"csv","z":"9859d967.3b9e48","name":"","sep":",","hdrin":true,"hdrout":true,"multi":"one","ret":"\\n","temp":"col1, col2","x":710,"y":280,"wires":[["f0b672e0.bf6da8"]]},{"id":"d035f2b5.848638","type":"http in","z":"9859d967.3b9e48","name":"downloads","url":"/downloads","method":"get","upload":false,"swaggerDoc":"","x":420,"y":340,"wires":[["f89d269b.ff39e","6315085a.802eb8"]]},{"id":"f89d269b.ff39e","type":"debug","z":"9859d967.3b9e48","name":"","active":true,"console":"false","complete":"false","x":440,"y":420,"wires":[]},{"id":"d27c7676.bf2ab8","type":"http response","z":"9859d967.3b9e48","name":"response","statusCode":"200","headers":{"content-type":"text/plain"},"x":860,"y":340,"wires":[]},{"id":"6315085a.802eb8","type":"ui_template","z":"9859d967.3b9e48","group":"935d095d.aca9d","name":"","order":0,"width":0,"height":0,"format":"<div ng-bind-html=\"msg.payload\"></div>\n<a href=\"~/TEST.CSV\">Download TEST.CSV</a>","storeOutMessages":true,"fwdInMessages":true,"templateScope":"local","x":720,"y":340,"wires":[["d27c7676.bf2ab8"]]},{"id":"935d095d.aca9d","type":"ui_group","z":"","name":"Data Export","tab":"3d7e03a4.b27b1c","disp":true,"width":"12"},{"id":"3d7e03a4.b27b1c","type":"ui_tab","z":"","name":"Dashboard","icon":"dashboard","order":1}]

I've already changed in the settings.js the httpStatic to: httpStatic: '/home/pi/~'

Furthermore: When I try to download it I receive this screen:

0 Likes

#2

You would need to put your csv file somewhere where the http server has access. Checkout the settings for httpstatic in your settings.js (and in the docs)

Also i would suggest not using ~ in the name

0 Likes

#3

Your flow is not importable - please read: How to share code or flow json

0 Likes

#4

I changed, it hope you can import it now.

0 Likes

#5

http static shouldn’t include ~

0 Likes

#6

I did something similar. Except the button.
In my case, the csv file lies on a local Share on a machine.
I solved it with the execute function and smbget https://www.samba.org/samba/docs/current/man-html/smbget.1.html

Works Fine this way :wink:

0 Likes

#7

Do you have an example of this?

0 Likes