File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes Opening Image from Uploaded file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Opening Image from Uploaded file" Watch "Opening Image from Uploaded file" New topic
Author

Opening Image from Uploaded file

Budi Saputra
Greenhorn

Joined: Feb 17, 2009
Posts: 7
i use library from www.jfileupload.com. it work for uploading and i put the uploaded file on c:\uploads.

i try to show that image on my page but it can't open.
it seems that the page can't open image outside the war file that i deploy on my web server application.

what path should i use to put the uploaded image to the war file so i can open that image on my page or how can i show the image on my page using my path.
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9321
    
  17

Budi, don't use a place outside the scope of your application to store the images. When uploading your file, give a relative math to a folder in your application. If you post your source code, then it would be easier to help you.

If indeed you use a folder outside the scope of your application, then you need to create a servlet which will serve the images to clients on requests...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
Show your code.

Thats fine to place images outside the application. Suppose, you have lot of images uploaded by users, consider those as user's data, and more are on the way. It simply means you use file system, instead of database, to store user's uploaded images, which is perfectly fine and have some advantages too that outweighs the disadvantages. Another point is, replacing the application war file with a new version, would result in loss of data, otherwise. Further, placing it somewhere else will even make backup/recovery less troublesome.
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
And yes, please post the exceptions, if any you are getting.
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
Use a servlet which reads the image from file system and writes it to response. It is in fact very simple.
You can find here an example: http://balusc.blogspot.com/2007/04/imageservlet.html
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Opening Image from Uploaded file