I’m looking for a solution for storing unique file names for a web application using Java Servlet.
What I need is to render profile images in a webpage, since I decided to store only file names in the database I have only to be sure they’re unique in the image folder: to achieve that I was thinking to name images and save them with a string name composed by the couple:
<user_id>_<hash>.<file-type>
In this manner I think I would be pretty sure there will be no collisions, since user_ids are already unique.
1) Is this solution sound?
2) What algorithm should I pick for this purpose?
I’d like to use it properly so code snippets would be very appreciated.
Thanks
Really simple approach would be to append
System.currentTimeMillis()to the userid. If userid is unique then it should be pretty safe.