Read data file with non local path

Hello...I need a function to read the content of a file that has a different path (it's located in app online),
the path is similar to this "data:text/plain;base64,c2FsdXQgICAuLmplIHN1aXMgSGFmc2EgQXJhYmJhdGU=", the 'file in' node can't recognize the path like this..So I'm wondering if I put this path as a variable in a function and read the file but I'm not good enough in JS ..any help?tst2

That is not a path. it is a bas64 encoded data

so you would split it at the comma and the base64decode everything after comma to get the text.

https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs

1 Like

The file nodes (as you have found) only read local files. For web based resources you probably need the http-request node - but again that needs a proper url - what you have is an inline resource that is a base64 encoded piece of text. You would need to extract and decode the text first and then use that as a url.

1 Like

A simple example

[{"id":"266aa7d2.820848","type":"change","z":"8d22ae29.7df6d","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"$base64decode($split(payload,\",\")[1])","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":280,"y":3920,"wires":[["2756679c.c38ed8"]]},{"id":"e80c63e9.b052e8","type":"inject","z":"8d22ae29.7df6d","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"data:text/plain;base64,c2FsdXQgICAuLmplIHN1aXMgSGFmc2EgQXJhYmJhdGU=","payloadType":"str","x":130,"y":3860,"wires":[["266aa7d2.820848"]]},{"id":"2756679c.c38ed8","type":"debug","z":"8d22ae29.7df6d","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":500,"y":3920,"wires":[]}]
1 Like

Thank you so much

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.