javascript - 使用 http 端点在 Node-RED 仪表板中显示本地镜像

标签 javascript html node-red

我需要使用 http 端点在 Node-RED 仪表板上显示图像。 我已完成以下操作:

  1. 将图像保存在/home/pi/Pictures 中。
  2. 在setting.js 文件中编辑了httpStatic:“/home/pi/Pictures”。
  3. 尝试在 html 图像标签中的 src 图像名称前使用斜杠“/” 没有“/”但没有任何作用。

这是我的流程供引用:

[
  {
    "id": "7b08a202.a1670c",
    "type": "http in",
    "z": "e5e5e9b.2a8cc18",
    "name": "",
    "url": "/display-image",
    "method": "get",
    "upload": false,
    "swaggerDoc": "",
    "x": 112,
    "y": 73,
    "wires": [
      [
        "35ca7d97.da9dd2"
      ]
    ]
  },
  {
    "id": "f8cf60ed.74b87",
    "type": "http response",
    "z": "e5e5e9b.2a8cc18",
    "name": "",
    "statusCode": "",
    "headers": {

    },
    "x": 458,
    "y": 70,
    "wires": [

    ]
  },
  {
    "id": "35ca7d97.da9dd2",
    "type": "template",
    "z": "e5e5e9b.2a8cc18",
    "name": "SLD View",
    "field": "payload",
    "fieldType": "msg",
    "format": "handlebars",
    "syntax": "mustache",
    "template": "<!DOCTYPE html>\n<html>\n    <body>\n        <img src=\"Barsu_SLD.png\" alt=\"Overview\" width=1000px; height=800px>\n    \n    </body>\n</html>",
    "output": "str",
    "x": 310,
    "y": 136,
    "wires": [
      [
        "f8cf60ed.74b87"
      ]
    ]
  },
  {
    "id": "2beda89c.ca2b98",
    "type": "ui_template",
    "z": "e5e5e9b.2a8cc18",
    "group": "d9e6ccf5.f58ab",
    "name": "Display Button",
    "order": 0,
    "width": 0,
    "height": 0,
    "format": "<!DOCTYPE html>\n<html>\n    <head>\n        <style>\n            .button {\n                background-color: #086A87;\n                border: none;\n                color: white;\n                padding: 16px 32px;\n                text-align: center;\n                text-decoration: none;\n                font-size: 16px;\n                margin: 3px 1px;\n                cursor: pointer;\n                border-radius: 4px;\n            }\n            .button_over:hover {\n                background-color: #187A97;\n                color: white;\n            }\n        </style>\n    </head>\n    <body>\n        \n        <a href=\"http://127.0.0.1:1880/BARSU-SLD/\" class=\"button button_over\" target=\"_blank\" >SLD View</a>    \n        \n    </body>\n </html>",
    "storeOutMessages": false,
    "fwdInMessages": true,
    "templateScope": "local",
    "x": 112,
    "y": 195,
    "wires": [
      [

      ]
    ]
  },
  {
    "id": "d9e6ccf5.f58ab",
    "type": "ui_group",
    "z": "",
    "name": "Test",
    "tab": "1474e3ec.fb238c",
    "disp": true,
    "width": "6"
  },
  {
    "id": "1474e3ec.fb238c",
    "type": "ui_tab",
    "z": "",
    "name": "Home",
    "icon": "dashboard"
  }
]

任何帮助都非常值得赞赏。

最佳答案

如果您有httpStatic设置为~/.node-red/public ,例如在 settings.js 中使用以下内容

httpStatic: path.join('', 'public'),

如果您有文件:~/.node-red/public/images/myimage.png

那么你的url应该使用html

<img src="/images/myimage.png">

注意开头的 /并且缺乏任何http://localhost:1880 。您不需要提供 http 部分,因为您的浏览器会自动为您匹配该部分。

另请注意,如果您设置了 httpRoot对于某些内容,您还需要在 URL 前添加该前缀。

关于javascript - 使用 http 端点在 Node-RED 仪表板中显示本地镜像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48623117/

相关文章:

javascript - ExtJS 6 : Validator on a textfield not working properly

javascript - Flask form onchange this.form.submit() 抛出 TypeError : 'HTMLString' object is not callable

php - 将表格单元格值放入 PHP post 中

node.js - Node-Red 中的最佳实践是否能够源源不断?

javascript - 页面刷新后,gapi 登录状态未保留在用户浏览器中

javascript - 正则表达式/javascript CamelCase 函数中的连字符

html - CSS 填充速记声明中的反斜杠

javascript - 更改 css 动画,使其在特定时间后自动运行

azure - Node-red:使用分析图像 API 将本地镜像发送到 Azure 的功能节点

node.js - 升级 Node 时出现问题 - 未找到 Node 红色启动