0

My Java application is using jetty running an embedded server, the idea being my software can then be controlled by a browser from a phone/ipad with the server running on PC/Mac ecetera.

I want the user to be able to browse folders on the server from webpage within their browser, not on their client so I was thinking that webdav might be the answer, but how do I even get started with this. All I want them to be able to do is view a browser tree of folders on the server and pick a folder, this folder is then stored in a Form text field and submitted to the server. That is all I need it to do.

So currently you can use file input type to allow users to browse for files on their computer, but I need the same functionality but for browsing files on the server.

<input type="file" name="img">

I realize this is not out of the box behaviour but I have seen it implemented before so how is it done ?

It seems the server would have to provide the file structure, I could try and create this in my backend but hopefully there is something that already done this. Then it has to be rendered on the front-end I assume there is already something for rendering a file structure ?

I found this question Server Side File Browsing which asks essentially the same question, however it is very old and I believe outdated.

Paul Taylor
  • 13,411
  • 42
  • 184
  • 351
  • Show us what you've already done... – Cedric Dec 11 '17 at 21:33
  • You can use the Java `File` APIs and the like to navigate and display the contents of the filesystem for your Java application. See [the javase tutorial on the subject](https://docs.oracle.com/javase/tutorial/essential/io/dirs.html). – Ryan Dec 11 '17 at 21:58
  • Its a web application, but now you say it i see you might be right,. I could present files to html page, but how to browse them in html – Paul Taylor Dec 11 '17 at 22:51
  • @Cedric I havent done anything yet, I cant see a way to get started. I was considering trying webdav but may that is not the right thing – Paul Taylor Dec 11 '17 at 22:52
  • Create a REST-API where you get the file/directory names from. Just send the files over TCP to the user (or create some php-ish download script) or read the files fully and display them. – Cedric Dec 12 '17 at 18:29
  • @Cedric Okay I can generate the file structure but what is the best way to display them, and seeing as the user can select any folder on the server Im concerned that the generated list is going to be very large and hence page loading slow so what is the best way to go about this. – Paul Taylor Dec 14 '17 at 09:40
  • Just show the first 30 results...? And add a search functionality. Just request the file structure of each subdirectory when the user tries to navigate to it – Cedric Dec 20 '17 at 14:26

1 Answers1

0

The solution I am implementing is to use jsTree on the client in ajax mode to contact the server as the user clicks on nodes so it only gets the data as required. The server code makes use of java FileVisitor class to construct the required part of the folder tree and return it jsTree in json format.

Paul Taylor
  • 13,411
  • 42
  • 184
  • 351