Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / August 2007

Tip: Looking for answers? Try searching our database.

Storing images for a web application.

Thread view: 
getsanjay.sharma@gmail.com - 05 Aug 2007 19:10 GMT
*** 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.
Daniel Pitts - 05 Aug 2007 19:22 GMT
On Aug 5, 11:10 am, getsanjay.sha...@gmail.com wrote:
> *** I apologize if this is a duplicate thread since I am having
> problems with my ISP***
[quoted text clipped - 14 lines]
> 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
[quoted text clipped - 23 lines]
> 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.
getsanjay.sharma@gmail.com - 06 Aug 2007 18:09 GMT
> On Aug 5, 11:10 am, getsanjay.sha...@gmail.com wrote:
>
[quoted text clipped - 65 lines]
> 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
Daniel Pitts - 06 Aug 2007 20:24 GMT
On Aug 6, 10:09 am, getsanjay.sha...@gmail.com wrote:

> > On Aug 5, 11:10 am, getsanjay.sha...@gmail.com wrote:
>
[quoted text clipped - 84 lines]
> 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.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.