Open Windows File

#1

We have code almost working to open an external file. The code below strips out the second colon. If I put in the second colon manually then I can get the file to open. Is there any way to get this to work?

var http = "http://file://///servername/AppDrive/temp/" + msg.payload;
msg.payload = http
return msg;

That code returns the URL below. When I manually put in the colon after "file" it works.
http://file/////servername/AppDrive/temp/filename.xml

My template is just html code to open the file in a window.

    <p><a href="{{msg.payload}}" target="_blank"><font color="yellow">Click Here to View the XML</font></a></p>

My goal is to send a list of Windows files using MQTT to the Linux Node Red, this is working. Then once I select a file I want to open that XML to view it.

0 Likes

#2

Not sure what is going on here. The code you posted (please put code between triple back-ticks, it is much easier to read and handle) doesn't result in the output you gave. The second colon is most certainly there.

Also, the XML link doesn't work - not sure if that is Discourse blocking it.

What is your Dashboard template code? We can't really help if we don't know that.

Here is some somewhat old info on building the correct URI's for Windows shared drives:

The problem, at least with Chrome, appears to be that Chrome prevents the downloading of local resources.

Not allowed to load local resource: file://192.168.1.162/eBooks/Interesting%20Authors.txt

Check your browser dev console.

0 Likes

#4

From everything we have read online we thought this would work. We tried Firefox and IE.

I am open to suggestions. I could create a process to copy the files to the Linux Node Red and read them locally.

I have exported my flow to give the whole picture.

[{"id":"a6008368.adda6","type":"mqtt in","z":"4b22c14.195024","name":"ICAN Configs","topic":"ICAN/Configs/#","qos":"2","broker":"e33b2c39.38e3f8","x":110,"y":600,"wires":[["21abf5c.78cda8a"]]},{"id":"d4fc626b.8fe548","type":"debug","z":"4b22c14.195024","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":1130,"y":640,"wires":[]},{"id":"21abf5c.78cda8a","type":"function","z":"4b22c14.195024","name":"tagStringsIntoArray","func":"rel_nl = msg.payload;\n\nvar rel_array = rel_nl.split(\"\\n\").map(String);\n\n//rel_array.unshift(\"Select a Rel. to Deploy\");\n//rel_array.unshift(\"\");\nrel_array = rel_array.splice(0, rel_array.length-1);\n//var relReverse_array = rel_array.reverse();\nmsg.payload = rel_array;\nreturn msg; ","outputs":1,"noerr":0,"x":310,"y":600,"wires":[["18033114.0eb7ef"]]},{"id":"18033114.0eb7ef","type":"change","z":"4b22c14.195024","name":"","rules":[{"t":"set","p":"options","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":520,"y":600,"wires":[["106ccfeb.812ca"]]},{"id":"106ccfeb.812ca","type":"ui_dropdown","z":"4b22c14.195024","name":"R3 ICAN Configs","label":"","place":"Select option","group":"8b937006.fcc07","order":0,"width":0,"height":0,"passthru":true,"options":[{"label":"","value":"","type":"str"}],"payload":"","topic":"","x":730,"y":600,"wires":[["d4f1c56c.a31b18"]]},{"id":"d4f1c56c.a31b18","type":"function","z":"4b22c14.195024","name":"build hyperlink","func":"//var file = \"file:////servername//AppDrive//temp//\" + msg.payload;\nvar http = \"http://file:////servername//AppDrive//temp/\" + msg.payload;\nmsg.payload = http\nreturn msg; ","outputs":1,"noerr":0,"x":940,"y":600,"wires":[["c33679b3.cb0128","d4fc626b.8fe548"]]},{"id":"c33679b3.cb0128","type":"ui_template","z":"4b22c14.195024","group":"8b937006.fcc07","name":"Display File","order":0,"width":0,"height":0,"format":"<p><a href=\"{{msg.payload}}\" target=\"_blank\"><font color=\"yellow\">Click Here to View the XML</font></a></p>","storeOutMessages":true,"fwdInMessages":true,"templateScope":"local","x":1130,"y":600,"wires":[[]]},{"id":"e33b2c39.38e3f8","type":"mqtt-broker","z":"","name":"MQTT","broker":"node-001@pxvapta001.directv.com","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"8b937006.fcc07","type":"ui_group","z":"","name":"ICAN","tab":"9cbdb8e.7c8ee48","order":2,"disp":true,"width":"7","collapse":true},{"id":"9cbdb8e.7c8ee48","type":"ui_tab","z":"","name":"R3","icon":"dashboard"}]
0 Likes

#5

I think that you will need to deliver the file via Node-RED rather than directly. Have a search through the archives for flows related to file downloads.

Service local files directly via the browser is dangerous at it potentially lets you span remote and local domains and so all to easily leak data. Delivering a file from an application server lets the server take care of the security.

0 Likes