• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

how to upload a image in particulart directory in web app. server

 
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am using Tomcat I am writing upload program to upload image in to he related directory. But it is storing in bin directory of tomcat, I have store in webapps folder. I am using IOStream to upload the bytes of image... any one help in the small issue....
thanks in advance
 
author and deputy
Posts: 3150
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by narasimharao konjeti:
I am using Tomcat I am writing upload program to upload image in to he related directory. But it is storing in bin directory of tomcat, I have store in webapps folder. I am using IOStream to upload the bytes of image... any one help in the small issue....
thanks in advance


You can specify the directory into which the file should store while constructing the IOStream like "C:\tomcat\webapps\examples\yourfilename.gif"
 
narasimharao konjeti
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear balaji, I did that it is working fine. But my problem, I have to take the path dynamically.
and i have to store the images in the server location. it will be change server to server..
thanks in advance
cheers
 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Tomcat stores the uploaded image files into the /bin directory since the Tomcat startup file is also in the /bin directory, and therefore the "ROOT" directory is there by default.
The way to do is that when you initialize your output stream, you need to put in an absolute path, something starts with a drive name.
I can see the destionation path is dynamic, how about you create your "ROOT" dir, say C:/Upload, and all the user-defined paths must append this "ROOT" dir instead.
Wendal
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Instead of writting the code you can use the jsp smartupload its tag lib which is freely availble.
Regards
Prashant
 
narasimharao konjeti
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
dear wendell and prasanth. I used smart tag. I am getting one exception called. some files not found. That is what I am uploading images using streams. and how can I change the default directory of tomcat. can I upload on selected directory in to server, if so how?
thanks in advance
cheers
 
Balaji Loganathan
author and deputy
Posts: 3150
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by narasimharao konjeti:
Dear balaji, I did that it is working fine. But my problem, I have to take the path dynamically.
and i have to store the images in the server location. it will be change server to server..
thanks in advance
cheers


Yes! you can get the path dynamically,
by using request.getContextPath() or
getServletContext().getRealPath("")
the former will give you the "/examples" as the path and the latter will give "C:\tomcat\webapps\examples\" as outputs for a windows system, it will also give "proper" paths for other operating systems.
Have fun.
FYI I got this from SnoopServlet.java under examples directory.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic