Discussion:
File upload directory
Dave Neil
2003-05-06 14:32:17 UTC
Permalink
I am trying to determine the best location for a directory to contain
uploaded images.

Should it be to a subdirectory within the webapp performing the upload or
should it go to a complete separate directory elsewhere on the server?

Uploading the images into a directory under the deployment directory makes
undeployment more difficult (removing the core of the web-app while leaving
the uploaded images) and also appears to make it impossible to deploy as a
war file.

It seems logical to me that uploaded files should go to a separate directory
on the server, but then
I have the problem that I want to display the uploaded images from within
the web-application. As I understand it, tomcat security prevents a
web-application from accessing files outside the directory in which it has
been deployed.

Has anyone got any experience in this area?
Thanks,
Dave.
Prabhakar, Achal
2003-05-06 14:47:17 UTC
Permalink
Dave,

I have a similar application in which I put the uploaded images in a
temporary staging area (/tmp). Once upload is complete and the application
has performed the necessary checks, it moves to a separate directory,
something like (/images/Repository).

As far as I know, Tomcat does not put any restrictions on directory access,
as long as the user under whom tomcat is running has permissions to access
the files everything should be ok.

-Achal


-----Original Message-----
From: Dave Neil [mailto:***@ipaccess.com]
Sent: Tuesday, May 06, 2003 9:32 AM
To: tomcat-***@jakarta.apache.org
Subject: File upload directory


I am trying to determine the best location for a directory to contain
uploaded images.

Should it be to a subdirectory within the webapp performing the upload or
should it go to a complete separate directory elsewhere on the server?

Uploading the images into a directory under the deployment directory makes
undeployment more difficult (removing the core of the web-app while leaving
the uploaded images) and also appears to make it impossible to deploy as a
war file.

It seems logical to me that uploaded files should go to a separate directory
on the server, but then
I have the problem that I want to display the uploaded images from within
the web-application. As I understand it, tomcat security prevents a
web-application from accessing files outside the directory in which it has
been deployed.

Has anyone got any experience in this area?
Thanks,
Dave.


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-***@jakarta.apache.org
For additional commands, e-mail: tomcat-user-***@jakarta.apache.org
Dave Neil
2003-05-06 15:09:40 UTC
Permalink
Thanks Achal, follow on question -

I am storing the path to the file in the DB and storing the image in the
file system.

If the image is outside the webapp directory structure then what form should
the file path be to allow the HTML/JSP code to display the image.

For example the path / corresponds to the directory
/usr/share/tomcat4/webapps/mywebapp/
If I want the images in /images/Repository what should the file path be?
/../../../../images/Repository/image.jpg ?

Dave.
Post by Prabhakar, Achal
-----Original Message-----
Sent: 06 May 2003 15:47
To: 'Tomcat Users List'
Subject: RE: File upload directory
Dave,
I have a similar application in which I put the uploaded images in a
temporary staging area (/tmp). Once upload is complete and the application
has performed the necessary checks, it moves to a separate directory,
something like (/images/Repository).
As far as I know, Tomcat does not put any restrictions on
directory access,
as long as the user under whom tomcat is running has permissions to access
the files everything should be ok.
-Achal
-----Original Message-----
Sent: Tuesday, May 06, 2003 9:32 AM
Subject: File upload directory
I am trying to determine the best location for a directory to contain
uploaded images.
Should it be to a subdirectory within the webapp performing the upload or
should it go to a complete separate directory elsewhere on the server?
Uploading the images into a directory under the deployment directory makes
undeployment more difficult (removing the core of the web-app
while leaving
the uploaded images) and also appears to make it impossible to deploy as a
war file.
It seems logical to me that uploaded files should go to a
separate directory
on the server, but then
I have the problem that I want to display the uploaded images from within
the web-application. As I understand it, tomcat security prevents a
web-application from accessing files outside the directory in which it has
been deployed.
Has anyone got any experience in this area?
Thanks,
Dave.
---------------------------------------------------------------------
---------------------------------------------------------------------
Sasha Borodin
2003-05-06 14:48:45 UTC
Permalink
Dave,

I write uploaded files to a database, not the file system. But before I
started doing that, I used the oreilly's COS package, where you can have the
uploaded file dumped to a directory, then processed; I told it dump stuff
under /tmp, and had no problem accessing those files afterwords.

Hope that helps,

-Sasha Borodin
Post by Dave Neil
I am trying to determine the best location for a directory to contain
uploaded images.
Should it be to a subdirectory within the webapp performing the upload or
should it go to a complete separate directory elsewhere on the server?
Uploading the images into a directory under the deployment directory makes
undeployment more difficult (removing the core of the web-app while leaving
the uploaded images) and also appears to make it impossible to deploy as a
war file.
It seems logical to me that uploaded files should go to a separate directory
on the server, but then
I have the problem that I want to display the uploaded images from within
the web-application. As I understand it, tomcat security prevents a
web-application from accessing files outside the directory in which it has
been deployed.
Has anyone got any experience in this area?
Thanks,
Dave.
---------------------------------------------------------------------
Tim Funk
2003-05-06 14:54:33 UTC
Permalink
It should be a directory (String) you look up at runtime via JNDI. That way a
Sysadmin can set this value in server.xml.

-Tim
Post by Dave Neil
I am trying to determine the best location for a directory to contain
uploaded images.
Should it be to a subdirectory within the webapp performing the upload or
should it go to a complete separate directory elsewhere on the server?
Uploading the images into a directory under the deployment directory makes
undeployment more difficult (removing the core of the web-app while leaving
the uploaded images) and also appears to make it impossible to deploy as a
war file.
It seems logical to me that uploaded files should go to a separate directory
on the server, but then
I have the problem that I want to display the uploaded images from within
the web-application. As I understand it, tomcat security prevents a
web-application from accessing files outside the directory in which it has
been deployed.
Has anyone got any experience in this area?
Thanks,
Dave.
---------------------------------------------------------------------
Prabhakar, Achal
2003-05-06 15:21:49 UTC
Permalink
Dave,

I use the normal Java File IO facilities to access the files as such the
file path should be the
normal file system path. Taking your example, the file path would simply be
/images/Repository/image.jpg.
The relative path is only valid when you are using the container facilities.
Outside the container, as would be the case if you were to use the java.io
classes, you have to provide the real file system path.
The disadvantage is that you will have to serve the files yourself, but that
is not a very big deal.

I am not very sure if Tomcat will allow it, but if it does then you can
create a symlink within your webapp directory to the real path and let the
container serve the files for you.

-Achal


-----Original Message-----
From: Dave Neil [mailto:***@ipaccess.com]
Sent: Tuesday, May 06, 2003 10:10 AM
To: Tomcat Users List
Subject: RE: File upload directory


Thanks Achal, follow on question -

I am storing the path to the file in the DB and storing the image in the
file system.

If the image is outside the webapp directory structure then what form should
the file path be to allow the HTML/JSP code to display the image.

For example the path / corresponds to the directory
/usr/share/tomcat4/webapps/mywebapp/
If I want the images in /images/Repository what should the file path be?
/../../../../images/Repository/image.jpg ?

Dave.
Post by Prabhakar, Achal
-----Original Message-----
Sent: 06 May 2003 15:47
To: 'Tomcat Users List'
Subject: RE: File upload directory
Dave,
I have a similar application in which I put the uploaded images in a
temporary staging area (/tmp). Once upload is complete and the application
has performed the necessary checks, it moves to a separate directory,
something like (/images/Repository).
As far as I know, Tomcat does not put any restrictions on
directory access,
as long as the user under whom tomcat is running has permissions to access
the files everything should be ok.
-Achal
-----Original Message-----
Sent: Tuesday, May 06, 2003 9:32 AM
Subject: File upload directory
I am trying to determine the best location for a directory to contain
uploaded images.
Should it be to a subdirectory within the webapp performing the upload or
should it go to a complete separate directory elsewhere on the server?
Uploading the images into a directory under the deployment directory makes
undeployment more difficult (removing the core of the web-app
while leaving
the uploaded images) and also appears to make it impossible to deploy as a
war file.
It seems logical to me that uploaded files should go to a
separate directory
on the server, but then
I have the problem that I want to display the uploaded images from within
the web-application. As I understand it, tomcat security prevents a
web-application from accessing files outside the directory in which it has
been deployed.
Has anyone got any experience in this area?
Thanks,
Dave.
---------------------------------------------------------------------
---------------------------------------------------------------------
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-***@jakarta.apache.org
For additional commands, e-mail: tomcat-user-***@jakarta.apache.org
Loading...