Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Struts Upload

 
Vinoo Varghese
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 314
2
Android Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thnaks guys
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic