开发者

How do I store fileLocation and folders in a web based file management system

开发者 https://www.devze.com 2022-12-26 07:23 出处:网络
I am trying to create a web application that will allow users to upload files online. I am using gwt while using hibernate for database communication. I am able to upload a file to a server, and store

I am trying to create a web application that will allow users to upload files online. I am using gwt while using hibernate for database communication. I am able to upload a file to a server, and store it on the server. What I want to do is to associate the files with a user.

I want the user to be able to create folders and store a file in sub folders. my logic was to use the composite pattern to store folders and fileLocations with a user but I am am finding it diff开发者_Go百科icult to implement this so I can show the files and folders within a gwt tree.

What would be the best way to implement a hierarchy of folders and information of the location of a file so it could be displayed in a gwt tree?

What I did have was a User would hold a reference to a root folder and then each sub folder could hold folders or fileLocations. I used the composite pattern to implement the file hierarchy, but when I want to display a the contents of a folder I need a for loop for each list. So if I had a folder within a folder within a folder, that would need 3 nested for loops to show the contents of my folders.

I would like something like this.

What is the best way to implement this file management system?


I assume you aren't actually storing the directories and subdirectores as actual, real-life directories and subdirectories on the server? If you are, I would just have Java iterate the filesystem on the server and return a lightweight client-side representation of the files and folders it found to your GWT front-end for display. Apache Commons IO (specifically FileUtils.iterateFiles, or FileUtils.listFiles, just below it) can help you here.

If you're trying to emulate a file system in a database, you will probably want to do some research on how modern file systems store and look up files and how to implement and iterate over such data structures (you'll need some sort of loop or recursion). Some research into B-trees may help, as may this database of data structures (trees will be most helpful).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号