1

I´m using the FileServlet from Omnifaces: http://showcase.omnifaces.org/servlets/FileServlet

It works fine and all my images appears in my webapp. But now I would like to change the link from the image because I would like to avoid that someone enter the path from another image:

For example: The path from one image is: myapp/imagesservlet/mypic1.jpg

-> Someone can enter myapp/imagesservlet/mypic2.jpg -> and got another image.

My files are stored as: mypic like mypic1.jpg, mypic2.jpg.....

Is there any chance to change the path and got also the correct image?

Marc Meister
  • 197
  • 2
  • 12

1 Answers1

0

Just use unpredictable autogenerated filenames. E.g. imgur also does that. This responsibility is actually beyond the OmniFaces FileServlet as all it does is just inspecting the passed-in filename and serving it up. You should change the passed-in filename to be an autogenerated one. Save if necessary the original filename somewhere else, e.g. in a SQL database, if necessary along with other metadata (content type, size, etc) so it can more efficiently be indexed and searched.

How to autogenerate a random string in Java is already covered in this Q&A: How to generate a random alpha-numeric string?

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555