I am using icefaces, ace:fileEntry component for uploading files from client and those files are being saved in file system, also I have my managedBean marked as sessionScope and it make sense that when user logs out and then log in back, he/she will not see their uploaded files.
I want to do two things:
- When user uploads file then I want to save that file to database also along with user Id or user session information.
- When user logs out and logs back in again then he/she should be able to see his/her uploaded files, currently files are not saved after user logs out?
- User can only see his or her uploaded files and not any random files.
My approach:
I am thinking of creating new table in database with file id, user id and file and so when file gets uploaded from client using ace fileEntry component then via my Hibernate, I would save file and user related information that I get from session to database, now when user logs out and logins back, I make query to database table with userId to get all his or her files.
Any thoughts or better suggestions for implementing this feature?
Create a separate subfolder for every user based on user ID.
You can use
File#mkdir()to create a subfolder if necessary.Then to get all uploaded files afterwards, just do
This way you don’t need another DB table and the users will always only see their own files.