You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by bhanu sistla <si...@yahoo.co.uk> on 2003/07/30 14:10:56 UTC

Uploading a file to server using struts

Hi All,
 
I have an urgent requirement. Has any body have the code how to upload a file to server using struts frame work.
 
Regards
Bhanu


---------------------------------
Want to chat instantly with your online friends? Get the FREE Yahoo!Messenger

Re: Uploading a file to server using struts

Posted by Andrew Geery <ge...@doc.state.sc.us>.
There is an example upload application in the struts distribution 
(struts-upload.war in the webapps directory)

bhanu sistla wrote:

>Hi All,
> 
>I have an urgent requirement. Has any body have the code how to upload a
>file to server using struts frame work.
> 
>Regards
>Bhanu
>
>
>---------------------------------
>Want to chat instantly with your online friends? Get the FREE
>Yahoo!Messenger
>
>  
>



---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


RE: Uploading a file to server using struts

Posted by Suresh Addagalla <su...@wipro.com>.
You can use this code in your Action class after declaring a form
element of type FormFile.

            FormFile file = (FormFile) theForm.get("theFile") ;

            String fileName = file.getFileName() ;
            int fileSize = file.getFileSize() ;

            if ( (fileName != null) && (!fileName.equals("")) ) {

                try {

                    if (fileSize != 0) {

                        File xmlFile = new File(uploadAreaTemp +
                                                File.separator +
                                                fileName) ;

                        FileOutputStream fos ;
                        fos = new FileOutputStream(xmlFile) ;
                        byte[] fileData = file.getFileData() ;
                        fos.write(fileData) ;
                        fos.close() ;

                } catch (Exception e) {}

> -----Original Message-----
> From: bhanu sistla [mailto:sistla_prakash@yahoo.co.uk] 
> Sent: Wednesday, July 30, 2003 5:41 PM
> To: struts-user@jakarta.apache.org
> Subject: Uploading a file to server using struts
> 
> 
> Hi All,
>  
> I have an urgent requirement. Has any body have the code how 
> to upload a file to server using struts frame work.
>  
> Regards
> Bhanu
> 
> 
> ---------------------------------
> Want to chat instantly with your online friends? Get the FREE 
> Yahoo!Messenger
> 


**************************Disclaimer************************************

Information contained in this E-MAIL being proprietary to Wipro Limited is 
'privileged' and 'confidential' and intended for use only by the individual
 or entity to which it is addressed. You are notified that any use, copying 
or dissemination of the information contained in the E-MAIL in any manner 
whatsoever is strictly prohibited.

***************************************************************************

---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org