• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Serving files outside document root

 
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do as bear suggested. A similar approach can work for uploading as well.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic