• 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 Up Image Outside of Root

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've got my first Struts project up and running with JNDI / Struts 1.2 Tomcat 5.0.27. I'm writing my 2nd generation of applications and am trying to address as many shortcomings of my 1st generation apps as possible.

So ... I am looking to ship my applications as WAR files. In this particluar application I need to upload images. Because the deployment of the WAR (in tomcat) seems to delete the previous release, I need somewhere permanent to store the uploaded images.

So I am planning to store the images outside of the war file / generated directory - and therefore above the application root - how do I serve these images to the systems users? Are there any prebuilt tags to do this? Should I leave it to the sysadmins to configure? I am really looking for a best practice. (I can construct the actual system path for the images)

Many thanks

Andrew
 
Ranch Hand
Posts: 119
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Andrew,

Not sure if this would be a problem for Struts, but accessing resources outside of the app often does cause problems.

I would tackle this is a different way. The images might not change currently, but may might do next year? I'd be inclined to include the images in your version control systems or code repository. Just package them up in your war & deploy them afresh each time. That way you can always be sure that the images are there, you're not relying on any sysadmin folks to look after them (i.e. delete them accidentally or fail to promote them into production), and you have the flexibility to change the images in a controlled menner if required to at a later date (which is almost certain to happen, even if you don't think so now)
 
andrew low
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Louise,

It's a requirement that images can be dynamically added to the system when its up - they are photographs of employees for our intranet - employee starts, record is added, and photo uploaded. Adding them into Source Control adds another person to the business process. It's only one example too - I also need to get resumes / cv's and store these in the same fashion - it would be a disaster if they were accidentally overwritten, so I'll need the same solution for a diffent application.

I'm thinking along the lines of a taglib that takes an absolute path and retrives the file as a stream into the appropriate destination ... ideally an existing one.

Cheers

Andrew
 
pie sneak
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This isn't really a Struts question, but I'll share what I know. I had to do a similar functionality in PHP before. The user would upload the photo through the app via a profile page. Each profile has its own folder.

When the photo was uploaded, I saved the file name to the database. The link to the photo then was always:
http://<myroot>/<profilefoldername>/<photonamefromDB.jpg>
 
andrew low
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK I have a solution for this.

Problem : deploying application as war file deletes all file content, including anything that's been dynamically added to the system - in this case photos of employees.

Solution : Use DownloadAction (added in Struts 1.2.6) - I downloaded the Struts source code for this and subsumed this single class into my application. Extending this class allows a file to be delivered as a stream to the browser directly from the file system.

I create a directory at the same level as the war file is unzipped to - therefore it doesn't get overwritten when the war file is re-released and I can write to it easily and return content using the DownloadAction.

This was my first clue DownloadAction wiki

In my current code, the file name is getFile.do - not ideal but I imagine its only a matter of time before I get this to work seemlessly.

Does anyone know where I should look for that? I'd guess either filters or url_rewriting.....

Cheers

Andrew
 
reply
    Bookmark Topic Watch Topic
  • New Topic