Hi everybody,

A while ago i posted a question concerning file uploads. My initial idea was to save all uploaded files in a directory of the web application. Craig R. McClanahan replied to my post with the following very interesting comment (thanks Craig!):

Craig R. McClanahan wrote:
> * You are not guaranteed that a particular servlet container
>   even *has* a concept of a directory in which the web app
>   is deployed -- for example, even Tomcat can execute a webapp
>   directly from the WAR file.  When you do that, getRealPath()
>   returns null instead of a pathname, and your calculations above
>   will trigger a NullPointerException.
>
> * Even when you know that your apps are being deployed in unpacked
>   directories, uploading things directly into that directory means
>   you have to be careful about redeployment when you update the app
>   -- the normal behavior of "delete the old directory and replace it
>   with the new app" wipes out any uploaded files.
>
> I would recommend defining a directory somewhere in your server to hold the
> uploaded files for a webapp, and then pass the pathname of this directory to
> your app as a context init parameter or something like that.  This approach
> deals with both of the problems identified above.

My question is, how can i specify such a directory outside my webapp root diretory so that my Action classes can still reference those files? Craig's idea about using a context init parameter sounds good but do i have to retrieve this parameter manually every time i want to use it?

Ideally i would like to specify the upload directory in a properties file and then use the value of this property to create a constant that can be used throughout the application. is this doable? if yes, how?

I'm also looking into storing the files in the database along with the meta information for the files. What are the pros / cons for this approach? At the moment there are about 100 files that i have to deal with and there are not a lot of new ones added. The file size ranges from some KB up to ca. 5 MB...

Any suggestions, tips and comments would be higly appreciated.

Thanks a lot,
Patrick





---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to