• 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

Accessing Uploaded Images in a System Folder

 
Greenhorn
Posts: 24
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I upload images to a folder on the server's hard drive. Next I would like to display them back to the user. My question is; is it possible to map a system folder to a context relative path? And how to it? Entry in web.xml perhaps? ie. from "C:\img\" to "/resources/image/" (Of course, I could open the files in Java and stream myself but why do that when the container can do it?)

Alternatively, would you recommend storing images in a database and stream from there instead.

Thank you for taking time to answer a really basic question, my regards.
 
Saloon Keeper
Posts: 27762
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Nonononononono!

Absolutely do NOT upload anything to your WAR directories! It's not guaranteed to work in all environments and even where it does, the first time you update the WAR all your uploaded files will get nuked. Always upload to an external directory outside of the webapp server environment. Preferably one whose path can be configured via a deployment context definition and not hard-coded into the application. Or, like you said, upload to a database or something.

A web server is not a file server. So you will need a simple servlet to copy files from your image repository back out to the remote client. I'm afraid there's no standard copy-file servlet, but it's a simple matter to create one.

As to whether it's better to keep images in files or as BLOBs in databases, you can hear plenty of argument over that one. Files have the advantage of being easier to access. However, if you have database records referencing the files, keeping everything in one place reduces problems where the 2 repositories get out of sync.
reply
    Bookmark Topic Watch Topic
  • New Topic