A file writing dilemma....!

A

andrew.kitchen

Hi,

I have a webapp that I deploy using a WAR file. This application needs
to write image files to disk when I upload images. These images
currently reside in my webapp, but of course this causes problems when
I want to deploy a new WAR as it throws the images away.

What I believe is the solition is to write the images to a different
context so that they will not be overwritten, rather than write the
images to a database. I don't need to link to these images directly
from my webapp's JSP as I will read the images in so that I can
dynamically create thumbnails and watermark them etc....

I have set-up a new context for the images and my webapp can connect to
it. However I cannot find any code or such that shows examples of how
to write or read files from another context. Can you do this from
within your main webapp, or do you need to invoke a servlet in the
other context to provide file IO?

Any help gratefully received :)

thanks in advance.
Andrew
 
I

Ingo R. Homann

Hi,

I'm not sure, if I understand you correctly, but why do you not want to
store the Image in the database?

BTW: In HttpServlet, there are methods to get the directory of a
webapplication where you could store files.

Ciao,
Ingo
 
A

andrew.kitchen

Hi Ingo,

I recon the images are best saved to disk than the database, especially
as I am using a remote shared server. If I were running this on my own
machine I might think differently. It is the backup issue and file
copying that move me towards having a file system solution, as I could
have several thousand images in a year's time.

I'll try and clarify the problem here:

I have a web application context deployed in a WAR file called
context1. This is the main application. I have configured a second
context called context2 which has a docBase outside of context1'.

Within the context1 application I have a Struts enabled JSP with a form
for submitting an image file. This form's corresponding action class,
when complete, will get the file and write it to a directory within
context2 of my chosing. I might have to create a new directory, but the
long and short of it is that it will be written to this context.

In context1's web application there will be another JSP that will
display the image, but via a servlet so that I can overlay watermarking
on the image and create a dynamic thumbnail.

I hope that makes things more clear?

Thanks in advance for your help.
Andrew
 
I

Ingo R. Homann

Hi,

Well, what about a system-parameter in which you specify the directory,
in which the images should be stored?

Ciao,
Ingo
 
A

andrew.kitchen

Ingo,

So you recon perhaps just setting a simple system parameter is the best
idea? I was trying to make it as neat as possible, but I suppose my way
is overcomplicating things.

I'll try and just write to a repository directory and see whether that
works.

thanks,
andrew
 
A

andrew.kitchen

Ingo,
BTW: In HttpServlet, there are methods to get the directory of a
webapplication where you could store files.

Which methods are these and can you give me an example?

Thanks,
Andrew
 
A

andrew.kitchen

Ah right - I had used this one already but had used "/" instread of "."

Thanks for that - I had already RTFM - I wasn't being a clown!

Andrew
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top