Get File Path with WebDev

Start by hardcoding the directory you care about into your Python endpoint.
Then, you could pay attention to the remainingPath request parameter in a Python endpoint:
https://docs.inductiveautomation.com/display/DOC81/Web+Dev#WebDev-PythonResources

If it's None, then this is a request to the 'root', so you're going to use Java's File class to list the child files in that directory:
https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/io/File.html#listFiles()
And assemble that into a JSON payload or whatever else.

If there is a remaining path, then you're going to try to find that file, load the file, and then write it to the request's output stream.

Be careful with file traversal! A malicious actor could pass a relative path like ../../../../etc/passwd to your endpoint!

To avoid this risk, I'd suggest taking advantage of our SecurePathUtils class.

2 Likes