• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Serving files outside document root

 
Erik Pragt
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all,

I have a quite simple question which I have a hard time solving. People can upload files (images) to my site. I'd like to display the images to the visitors of the site, but I do not want to store the images in the document root, but outside of it.

Does anyone know how to accomplish such a task? Do I have to work with different RequestDispatchers, or is there some other way?

Thanks, Erik
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65129
92
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's not difficult to write a servlet that will read the file off the disk and send the contents to the response output.
 
Erik Pragt
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Bear,

Thanks for your reply. Probably it's not so hard, but is it the only way, or are there other ways to do so?

Erik
 
Jeroen Wenting
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
think about it.
If a webserver could serve files from any location on the system it's running on that would be a massive security leak.

Many application servers won't even allow servlets (or PHP, CGI, whatever) to access any files outside their application scope without special settings in the server configuration for that very reason.
 
Erik Pragt
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeroen, I agree with you, it could be a security hole, but this could maybe be prevented by the Security Manager or the file system.

Maybe you have a suggestion than how to handle file uploads and be able to present the upload files to other users?

Any help would be greatly appreciated, and thanks for your suggestions so far.
 
Jeroen Wenting
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do as bear suggested. A similar approach can work for uploading as well.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic