node-RED-dashboard:如何下载使用文件输出节点创建的 csv 文件?
node-RED-dashboard: How do I download a csv file created with a file output node?
我的目标是显示指向 csv 文件的链接,以便最终用户可以下载它们。
所以我创建了一个 csv 文件并使用文件输出节点保存它,但我找不到允许最终用户单击 link/button 来下载它的方法。我尝试了以下流程,但它指向 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}]
我预计这与绝对路径有关,但我不知道节点红色 Web 服务器的根在文件系统中的位置...
如有任何帮助,我们将不胜感激。
干杯,
西蒙
您的 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 服务器可以写入的某个绝对位置。然后重新启动 node-red,并修改您的流程以将 CSV 文件输出到此目录。您在此位置下创建的任何 files/folders 现在都可以由 node-red express 服务器提供服务。
当您的 node-red 服务器启动时,它将打印出用于提供静态文件的绝对路径——例如,在我的项目中它显示:
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下载了=>
http://localhost:1880/downloads/test.csv
我的目标是显示指向 csv 文件的链接,以便最终用户可以下载它们。
所以我创建了一个 csv 文件并使用文件输出节点保存它,但我找不到允许最终用户单击 link/button 来下载它的方法。我尝试了以下流程,但它指向 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}]
我预计这与绝对路径有关,但我不知道节点红色 Web 服务器的根在文件系统中的位置...
如有任何帮助,我们将不胜感激。
干杯, 西蒙
您的 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 服务器可以写入的某个绝对位置。然后重新启动 node-red,并修改您的流程以将 CSV 文件输出到此目录。您在此位置下创建的任何 files/folders 现在都可以由 node-red express 服务器提供服务。
当您的 node-red 服务器启动时,它将打印出用于提供静态文件的绝对路径——例如,在我的项目中它显示:
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下载了=> http://localhost:1880/downloads/test.csv