Discussion:
Unable to access files outside Webapp directory in tomcat
asingla4
2009-08-30 16:34:08 UTC
Permalink
Hi All,

I am developing a web application with JDK 1.6 and Tomcat 6.0.

I have kept all the documents and images outside the root directory of the
application.
How can I access these files in my application. Please suggest

Thanks

Akash Singla
TheDaedals.com
--
View this message in context: http://www.nabble.com/Unable-to-access-files-outside-Webapp-directory-in-tomcat-tp25213157p25213157.html
Sent from the Tomcat - User mailing list archive at Nabble.com.
Christopher Schultz
2009-08-31 16:00:15 UTC
Permalink
Akash,
Post by asingla4
I have kept all the documents and images outside the root directory
of the application. How can I access these files in my
application[?]
What have you already tried?

- -chris
asingla4
2009-09-01 17:36:41 UTC
Permalink
Hi,

Initially, I was accessing the files using the absolute path, but this way
I'm unable to download the files through my web Page (the download image on
the page would require a relative path as src.)

So, eventually, I haven't been able to try anything.

Akash
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Akash,
Post by asingla4
I have kept all the documents and images outside the root directory
of the application. How can I access these files in my
application[?]
What have you already tried?
- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iEUEARECAAYFAkqb848ACgkQ9CaO5/Lv0PDYKQCVFFj6UJlSTTEFn0qemuv5J3R0
3gCggNJlZP3lGSIgZ+syit2FrKcV/88=
=yW0Z
-----END PGP SIGNATURE-----
---------------------------------------------------------------------
--
View this message in context: http://www.nabble.com/Unable-to-access-files-outside-Webapp-directory-in-tomcat-tp25213157p25244051.html
Sent from the Tomcat - User mailing list archive at Nabble.com.
Christopher Schultz
2009-09-01 18:06:48 UTC
Permalink
Akash,
Post by asingla4
Initially, I was accessing the files using the absolute path
Accessing the files with what? A fork and knife?
Post by asingla4
but this way
I'm unable to download the files through my web Page (the download image on
the page would require a relative path as src.)
Are you trying to read a file off the disk using something like
FileInputStream, or are you trying to access a file from the server
using a URL from a browser?

These are very basic questions whose answers will certainly help solve
your problem.
Post by asingla4
So, eventually, I haven't been able to try anything.
:(

- -chris
asingla4
2009-09-02 05:32:58 UTC
Permalink
Hi,

I have my Web application installed in C:\Tomcat\webapp\ROOT.
Now, through the Web page of this application, the user uploads an image
which the application saves in C:\files folder using ImageIO class of JAVA.
Now as soon as the file is uploaded, there should be a download button
enabled for this uploaded image.
If the user hits download, he should be able to download the file he
uploaded.

I'm done with saving the file to C:\files but I don't know how to make it
downloadable when the download button is clicked because the files folder is
outside the webapp directory.

I hope this explains my issue.

Thanks
Akash.
Post by Christopher Schultz
Are you trying to read a file off the disk using something like
FileInputStream, or are you trying to access a file from the server
using a URL from a browser?
These are very basic questions whose answers will certainly help solve
your problem.
--
View this message in context: http://www.nabble.com/Unable-to-access-files-outside-Webapp-directory-in-tomcat-tp25213157p25251880.html
Sent from the Tomcat - User mailing list archive at Nabble.com.
Michael Ludwig
2009-09-02 12:16:59 UTC
Permalink
Post by asingla4
I'm done with saving the file to C:\files but I don't know how to make
it downloadable when the download button is clicked because the files
folder is outside the webapp directory.
Please read this thread:

providing downloading functionality for a file which is on disk
http://markmail.org/thread/ixx6oxtkdukp4xtf

Especially Chuck's reply:

RE: providing downloading [...] - Caldarale, Charles R
http://markmail.org/message/6e2vxa3eixd5cvgf
--
Michael Ludwig
Christopher Schultz
2009-09-03 21:07:13 UTC
Permalink
Akash,
Post by asingla4
I have my Web application installed in C:\Tomcat\webapp\ROOT.
Now, through the Web page of this application, the user uploads an image
which the application saves in C:\files folder using ImageIO class of JAVA.
Aah, the magic of using an image API to save byte streams. You didn't
need that extra CPU time for anything, did you?
Post by asingla4
Now as soon as the file is uploaded, there should be a download button
enabled for this uploaded image.
If the user hits download, he should be able to download the file he
uploaded.
Okay, so you want to allow remote clients to access uploaded files
through a URL pattern. No problem.
Post by asingla4
I'm done with saving the file to C:\files but I don't know how to make it
downloadable when the download button is clicked because the files folder is
outside the webapp directory.
You have a few options:

1. Create a new context called, say, "files" and point it at c:\files.
You can do this by creating
CATALINA_BASE/conf/[servicename]/[hostname]/files.xml with this content:

<Context docBase="C:\files" />

OR

2. Write a servlet mapped to /files/* (or whatever) that looks-up files
in /files and just streams them to the client.

#2 would be better if you need to be logged-in to your webapp in order
to download files. #1 is more convenient because you don't have to write
any code.

Hope that helps,
- -chris

Loading...