jQuery in Action, 2nd edition*
The moose likes Struts and the fly likes Struts Upload Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts Upload " Watch "Struts Upload " New topic
Author

Struts Upload

Vinoo Varghese
Greenhorn

Joined: Dec 22, 2002
Posts: 2
Hi ,
Got a doubt in Struts upload.The scenario is as follows:
There is a admin module which exists on the client side.On uploading an image from the client side ,this has to be uploaded on the server.I tried writing directly to the url(www.xyz.com/pack1/pack2/images/"+imagefilename using FileOutputStream.However,I got the error..File does not exist.Is there any way,I can upload the image onto the server side?
Thanks in Advance...
Darryl A. J. Staflund
Ranch Hand

Joined: Oct 06, 2002
Posts: 303
Hi there,
Take a look at the examples that come with the Struts download. One of them shows how to upload files using Struts.
Darryl
Paul Woods
Greenhorn

Joined: Nov 15, 2002
Posts: 23
Hi.
Something I found out the hard way to be aware of is that different servers are configured differently regarding paths and uploads, so if you get something to work in development, it doesn't mean it will be correct when deployed.
Having said that, what worked for me is the following:
// FIND HARD PATH TO ROOT DIRECTORY OF WEBAPP
String pathTranslated = request.getPathTranslated();
int lastIndex = pathTranslated.lastIndexOf("/");lastIndex = lastIndex + 1;
String newPath = pathTranslated.substring(0, lastIndex);
Then, add the directory you want to put the pics in to the path above, plus the file name, and write:
FileOutputStream pictureOS = new FileOutputStream(path + "pics/" + newPictureName[count]);
pictureOS.write(pictures[count].getFileData());// write data to disk
pictureOS.flush();
pictureOS.close();
Vinoo Macmillan
Greenhorn

Joined: May 21, 2003
Posts: 4
Thnaks guys
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Struts Upload
 
Similar Threads
Image compression on client side
Creating File object problem
Upload image
Client side image uploading from server servlet
Uploading & displaying images using Struts