node-RED-dashboard:如何下载使用文件输出节点创建的csv文件?

时间:2017-12-20 16:37:17

标签: file download export dashboard node-red

我的目标是显示csv文件的链接,以便最终用户可以下载它们。

所以我创建了一个csv文件并使用文件输出节点保存它,但我找不到允许最终用户单击链接/按钮下载它的方法。我尝试了以下流程,但它指向http://localhost:1880/ui/~/TEST.CSV

[{"id":"3aff08aa.8731d8","type":"inject","z":"a24aefdf.d606e","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":120,"y":100,"wires":[["1541e37c.3072dd"]]},{"id":"1541e37c.3072dd","type":"function","z":"a24aefdf.d606e","name":"","func":"msg.payload = {};\nmsg.payload = {\"col1\": 1, \"col2\": 2};\nreturn msg;","outputs":1,"noerr":0,"x":270,"y":100,"wires":[["2d045a05.efbef6"]]},{"id":"12ba838c.dcd18c","type":"file","z":"a24aefdf.d606e","name":"TEST.CSV","filename":"~/TEST.CSV","appendNewline":true,"createDir":true,"overwriteFile":"true","x":570,"y":100,"wires":[]},{"id":"2d045a05.efbef6","type":"csv","z":"a24aefdf.d606e","name":"","sep":",","hdrin":true,"hdrout":true,"multi":"one","ret":"\\n","temp":"col1, col2","x":410,"y":100,"wires":[["12ba838c.dcd18c"]]},{"id":"5a9db6ab.f35b28","type":"http in","z":"a24aefdf.d606e","name":"downloads","url":"/downloads","method":"get","upload":false,"swaggerDoc":"","x":120,"y":160,"wires":[["7291d925.cfc9b8","ccef1ce3.900b8"]]},{"id":"7291d925.cfc9b8","type":"debug","z":"a24aefdf.d606e","name":"","active":true,"console":"false","complete":"false","x":140,"y":240,"wires":[]},{"id":"1916b0d1.3c55ff","type":"http response","z":"a24aefdf.d606e","name":"response","statusCode":"200","headers":{"content-type":"text/plain"},"x":560,"y":160,"wires":[]},{"id":"ccef1ce3.900b8","type":"ui_template","z":"a24aefdf.d606e","group":"a1588fc.a8dc47","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":420,"y":160,"wires":[["1916b0d1.3c55ff"]]},{"id":"a1588fc.a8dc47","type":"ui_group","z":"","name":"Data Export","tab":"ea941605.788c18","disp":true,"width":"12"},{"id":"ea941605.788c18","type":"ui_tab","z":"","name":"Dashboard","icon":"dashboard","order":1}]

我希望这与绝对路径有关,但我不知道节点红色网络服务器的根目录在文件系统中...

感谢任何帮助。

干杯, 西蒙

1 个答案:

答案 0 :(得分:1)

settings.js文件中有一个部分,默认情况下为:

// When httpAdminRoot is used to move the UI to a different root path, the
// following property can be used to identify a directory of static content
// that should be served at http://localhost:1880/.
//httpStatic: '/home/nol/node-red-dashboard/',

如果您还没有这样做,请取消注释httpStatic行并将目录路径设置为您的节点红色服务器可以写入的某个绝对位置。然后重新启动node-red,并修改流程以将CSV文件输出到此目录。您在此位置下创建的任何文件/文件夹现在都可以由node-red express服务器提供。

当您的节点红色服务器启动时,它将打印出用于提供静态文件的绝对路径 - 例如,在我的项目中显示:

13 Jan 12:06:45 - [info] Settings file  : C:\NODE\node_red_ui\settings.js

<强> 13 Jan 12:06:45 - [info] HTTP Static : C:\NODE\node_red_ui\public

13 Jan 12:06:45 - [info] User directory : C:\NODE\node_red_ui
13 Jan 12:06:45 - [info] Flows file     : C:\NODE\node_red_ui\flows_ENTLAPTOP18.json
13 Jan 12:06:45 - [info] Dashboard using development folder
13 Jan 12:06:45 - [info] Server now running at http://localhost:1880/admin/
13 Jan 12:06:45 - [info] Starting flows

因此,如果我创建文件C:\NODE\node_red_ui\public\downloads\test.csv

然后它可以通过url =&gt;下载 http://localhost:1880/downloads/test.csv