2017-01-23 40 views
1

我使用node-red創建應用程序並使用node-red-dashboard創建UI。節點紅色儀表板包含圖像

我已經包含了一些api調用,並基於響應我想更改模板控件的圖像源。

<img src="/home/pi/Destkop/WeatherImages/sun.png">

所以我用的絕對路徑的形象。但圖像沒有被加載。有一個符號表明圖像的來源設置爲localhost:1880/sun.png

我需要放置圖像的位置?我需要使用什麼路徑?

回答

2

由於瀏覽器訪問頁面可能與Node-RED運行的計算機不在同一臺計算機上,因此無法使用本地路徑來處理Node-RED中內置的Web服務器提供的文件。

settings.js文件(它將在〜/ .node-red中)有一個名爲httpStatic的設置,您可以使用它來指定Node-RED將服務器提供靜態內容的目錄。

... 
// 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-static/', 
... 

如果設置爲/ home/PI/Destkop/WeatherImages如下:

... 
// 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/pi/Desktop/WeatherImages', 
... 

然後你可以設置圖片src如下:

<img src="/sun.png"> 
+0

設置後曾任職' httpAdminRoot'從默認的'FALSE'爲'真' - 在文檔中看着它:http://nodered.org/docs/configuration –

+0

儀表板嘗試顯示'HTTP://raspberrypi.local:1880/UI /陽光即使我指定了''。 –

+0

這很可能是一個緩存問題 – hardillb