This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
narasimharao konjeti
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • 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
 
Balaji Loganathan
author and deputy
Bartender
Posts: 3150
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
Wendal Park
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • 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
 
PRASHANT HEGU
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • 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
  • 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
Bartender
Posts: 3150
  • Mark post as helpful
  • send pies
  • 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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!