Storing images for a web application.

  • Thread starter getsanjay.sharma
  • Start date
G

getsanjay.sharma

*** I apologize if this is a duplicate thread since I am having
problems with my ISP***

Hello to all Java programmers out there.

I am currently writing a web application which allows the user to
upload files on the server as their avatar. I am using JBoss 4 as my
application server, Java 1.5, MS Access as my DB (if you would be kind
enough to call it that) and Apache commons FileUpload module.

I have been successful in saving the file to the disk at an absolute
location (c:/photos) but am at a loss on how to save it to my projects
'image' folder i.e. the path relative to my application root
directory. I have a folder 'image' in the application's root directory
but am unable to store the file at that location. I tried various ways
of obtaining the path but to no avail. Also since I am using WAR files
for running project, I have to enter the image in the WAR file but
have no idea on how to do that.

Also I have a host of options when it comes to serving the images back
to the client but I am really confused as to which one is the more
feasible one.

1. I can use the InputStream to the file which the client uploads,
provide it to the setBinaryStream() function of Prepared Statement and
allow it to do its work. But the problem here is that each time the
image has to be displayed, I would have to hit the database and fetch
the image using the byte based approach.

2. I have heard that images / vidoes are BLOBS but I have no idea on
how to insert or retrieve such blob data from the database. Again, I
am sure there would be some kind of overhead involved while fetching
them.

3. I can store the images to a given location on my hard drive (the
problem above) and just provide its path to the src attribute of the
image tag, plain and simple.

I am pretty much confused on how to save the file to the given
location and which alternative to choose.

I would really appreciate if someone would lend me a helping hand in
this situation.

Thanks and regards,
S T S.
 
D

Daniel Pitts

*** I apologize if this is a duplicate thread since I am having
problems with my ISP***

Hello to all Java programmers out there.

I am currently writing a web application which allows the user to
upload files on the server as their avatar. I am using JBoss 4 as my
application server, Java 1.5, MS Access as my DB (if you would be kind
enough to call it that) and Apache commons FileUpload module.

I have been successful in saving the file to the disk at an absolute
location (c:/photos) but am at a loss on how to save it to my projects
'image' folder i.e. the path relative to my application root
directory. I have a folder 'image' in the application's root directory
but am unable to store the file at that location. I tried various ways
of obtaining the path but to no avail. Also since I am using WAR files
for running project, I have to enter the image in the WAR file but
have no idea on how to do that.
Its been my experience that the WAR file is exploded and then
"forgotten" about. You generally don't want to dynamically update
these files.
Also I have a host of options when it comes to serving the images back
to the client but I am really confused as to which one is the more
feasible one.

1. I can use the InputStream to the file which the client uploads,
provide it to the setBinaryStream() function of Prepared Statement and
allow it to do its work. But the problem here is that each time the
image has to be displayed, I would have to hit the database and fetch
the image using the byte based approach.

2. I have heard that images / vidoes are BLOBS but I have no idea on
how to insert or retrieve such blob data from the database. Again, I
am sure there would be some kind of overhead involved while fetching
them.

3. I can store the images to a given location on my hard drive (the
problem above) and just provide its path to the src attribute of the
image tag, plain and simple.

I am pretty much confused on how to save the file to the given
location and which alternative to choose.

I would really appreciate if someone would lend me a helping hand in
this situation.

Thanks and regards,
S T S.

I'm not sure about JBoss, but I know that Resin can serve actual
files, not just JSP/Servlets. Just figure out the absolute path to
that directory, and save the files there. That way you can just use
an <img src="/path/to/image.png"/>


Where I work, we generally put uploaded images into a docroot that is
served by Apache, and we also have Apache reverse-proxy to our webapp
containers.

For our higher-volume (requests per second) upload sites, we store
them into a specially created image/video file system. The whole
architecture is far to complicated to get into here, and I'm not sure
if its proprietary to my employer or not, so I won't expand on it.

Hope this helps,
DAniel.
 
G

getsanjay.sharma

Its been my experience that the WAR file is exploded and then
"forgotten" about. You generally don't want to dynamically update
these files.












I'm not sure about JBoss, but I know that Resin can serve actual
files, not just JSP/Servlets. Just figure out the absolute path to
that directory, and save the files there. That way you can just use
an <img src="/path/to/image.png"/>

Where I work, we generally put uploaded images into a docroot that is
served by Apache, and we also have Apache reverse-proxy to our webapp
containers.

For our higher-volume (requests per second) upload sites, we store
them into a specially created image/video file system. The whole
architecture is far to complicated to get into here, and I'm not sure
if its proprietary to my employer or not, so I won't expand on it.

Hope this helps,
DAniel.

Thanks a lot Daniel, I do realize that your architecture is
proprietary but still thanks for the tip. But the problem here is that
I am using JBoss(not Resin) and I have always thought that hardcoding
the image path would be a *bad* programming practice.

I tried various ways of storing the image in terms of the relative
path of the application but it just ends up in the JBoss directory. I
tried different 'getPath...' methods of request, response but failed
to get the path of the application.

This feat of handling of uploaded files and which approach to follow
is turning out to be a real feat for me. I guess its a limitation of
the WAR file that images can _never_ be stored in the root folder. :(

Any ideas would be appreciated.

Thanks and regards,
S T S
 
D

Daniel Pitts

Thanks a lot Daniel, I do realize that your architecture is
proprietary but still thanks for the tip. But the problem here is that
I am using JBoss(not Resin) and I have always thought that hardcoding
the image path would be a *bad* programming practice.

I tried various ways of storing the image in terms of the relative
path of the application but it just ends up in the JBoss directory. I
tried different 'getPath...' methods of request, response but failed
to get the path of the application.

This feat of handling of uploaded files and which approach to follow
is turning out to be a real feat for me. I guess its a limitation of
the WAR file that images can _never_ be stored in the root folder. :(

Any ideas would be appreciated.

Thanks and regards,
S T S

I really don't know about JBoss. you might look at there
documentation on how to serve flat files.
 

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,994
Messages
2,570,223
Members
46,810
Latest member
Kassie0918

Latest Threads

Top