在某个Node-red 工程中,需要构建一个用于下载信息的界面,
基于之前的HTTP的内容使用如下代码
步骤:
1,先构建一个html的页面,存储数据
2.构建一个下载的link,link到数据中,
代码
结果,;
一个页面用于显示内容
另一个页面用于下载显示内容的页面
[
{
"id": "4be6a292245681be",
"type": "inject",
"z": "668be90ba6e93eaa",
"name": "",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": true,
"onceDelay": 0.1,
"topic": "",
"payload": "",
"payloadType": "date",
"x": 190,
"y": 800,
"wires": [
[
"03e5c554d454aca5"
]
]
},
{
"id": "434ccc65670bb773",
"type": "http in",
"z": "668be90ba6e93eaa",
"name": "",
"url": "/tryde",
"method": "get",
"upload": true,
"swaggerDoc": "",
"x": 200,
"y": 960,
"wires": [
[
"c5dee37b8b710af4"
]
]
},
{
"id": "ff63e569bf5413f2",
"type": "http response",
"z": "668be90ba6e93eaa",
"name": "",
"statusCode": "",
"headers": {},
"x": 630,
"y": 960,
"wires": []
},
{
"id": "c5dee37b8b710af4",
"type": "template",
"z": "668be90ba6e93eaa",
"name": "html",
"field": "payload",
"fieldType": "msg",
"format": "handlebars",
"syntax": "mustache",
"template": "<a href=\"http://127.0.0.1:1880/trydedddd.123.txt\" download=\"\\\\data\\\\1234567890.txt\">点击下载</a>\n",
"output": "str",
"x": 450,
"y": 960,
"wires": [
[
"ff63e569bf5413f2"
]
]
},
{
"id": "4af27745992a6e44",
"type": "comment",
"z": "668be90ba6e93eaa",
"name": "构建下载程序",
"info": "",
"x": 150,
"y": 680,
"wires": []
},
{
"id": "6e8a02ac9fe76da5",
"type": "http in",
"z": "668be90ba6e93eaa",
"name": "",
"url": "/trydedddd.123.txt",
"method": "get",
"upload": true,
"swaggerDoc": "",
"x": 220,
"y": 880,
"wires": [
[
"f9d78bb735928c8e"
]
]
},
{
"id": "6d10b72668d79abc",
"type": "http response",
"z": "668be90ba6e93eaa",
"name": "",
"statusCode": "",
"headers": {},
"x": 630,
"y": 880,
"wires": []
},
{
"id": "f9d78bb735928c8e",
"type": "function",
"z": "668be90ba6e93eaa",
"name": "",
"func": "msg.payload=flow.get(\"aaaa\")\n\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 460,
"y": 880,
"wires": [
[
"6d10b72668d79abc"
]
]
},
{
"id": "03e5c554d454aca5",
"type": "function",
"z": "668be90ba6e93eaa",
"name": "",
"func": "var s='<html> <head>'\nvar a=''\n\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 420,
"y": 800,
"wires": [
[
"ed1dfd7eadfd1a20"
]
]
},
{
"id": "ed1dfd7eadfd1a20",
"type": "change",
"z": "668be90ba6e93eaa",
"name": "",
"rules": [
{
"t": "set",
"p": "aaaa",
"pt": "flow",
"to": "payload",
"tot": "msg"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 650,
"y": 800,
"wires": [
[]
]
},
{
"id": "db1b1161d6d7cb0a",
"type": "comment",
"z": "668be90ba6e93eaa",
"name": "1.Get data",
"info": "",
"x": 180,
"y": 760,
"wires": []
},
{
"id": "78b43e978261da05",
"type": "comment",
"z": "668be90ba6e93eaa",
"name": "2.build the web",
"info": "",
"x": 220,
"y": 840,
"wires": []
},
{
"id": "97e4fe4ac789daf0",
"type": "comment",
"z": "668be90ba6e93eaa",
"name": "3.download the data",
"info": "",
"x": 210,
"y": 920,
"wires": []
}
]