Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to implement file upload and download in struts2

 
sunil gupta
Greenhorn
Posts: 21
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello,

i want to implement file upload and download functioality in my application using struts2. i tried to use the examples from showcase and it seems to be working but they are static and i m not able to find some good example. if any body has implemented this functionality please share with me or post some good example.

I have few specific question.

1. when i m uploading a file what should be the path to store so that it can be downloaded also. should it be under tomcat or anywhere it can be saved.

2. when i am downloading a file it seems it should be under tomcat/webapp/project. that means it should be saved here only. i m not sure how will it work.

If any body have done it please help. it is very urjent.

thanks in advance.

Sunil
 
Shweta Baranwal
Greenhorn
Posts: 18
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Sunil,

To download file, the file should be present at the location where server is running because when any user will click on download button , the action present in server will be called and it will do whole processing .
I have done the same thing. In my application first of all i fetched the file from database and stored it in the location where tomcat server is running and then click of download button this this file will be downloaded.
Here is my code to save a file at server location :-

File file=new File("abc.jpg");
file.createNewFile();

this code will automatically create the file where server is running


hopefully this will help U.

 
Bilal A. Siddiqui
Ranch Hand
Posts: 53
Android Chrome Eclipse IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Sunil

I am using this code for file uploading.




You can find this code on the official web site of Struts 2 in action by manning publication.

and yes you have to save the file in tomcat itself, as per my knowledge.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
File uploading is handled by the framework; there's no need to read an input stream:

http://struts.apache.org/2.x/docs/file-upload.html

Uploaded files can be put anywhere.

Downloading files may be handled by the "stream" result:

http://struts.apache.org/2.0.14/docs/stream-result.html

or written directly to the response.
 
Bilal A. Siddiqui
Ranch Hand
Posts: 53
Android Chrome Eclipse IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks David.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic