struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dave Newton <new...@pingsite.com>
Subject Re: Multiple uploads / attachements
Date Tue, 03 May 2005 20:36:18 GMT
Abdullah Jibaly wrote:

>Does anyone have an example/pointers of uploading multiple files at one time?
>  
>
I have several forms using DynaValidatorAtionForm that have two file 
uploads. There's not much interesting going on, though, the framework is 
doing the majority of the work for me.

A form bean, trimmed:

    <form-bean name="eventbean" 
type="org.apache.struts.validator.DynaValidatorActionForm">
      <form-property name="headerFile" 
type="org.apache.struts.upload.FormFile" />
      <form-property name="cssFile" 
type="org.apache.struts.upload.FormFile" />
    </form-bean>

The form in the JSP is declared to be a multipart.
            
Processing the upload. trimmed:

        FormFile cssFile = (FormFile) form_.get("cssFile");
        FormFile headerFile = (FormFile) form_.get("headerFile");
        //...
        Upload.uploadFormFile(cssFile, root);
        Upload.uploadFormFile(headerFile, root);

uploadFormFile, trimmed:

            InputStream instream = file_.getInputStream();
            byte[] contents = new byte[file_.getFileSize()];
            instream.read(contents);
            File outputFile = new File(root_ + "/" + file_.getFileName());
            FileOutputStream outstream = new FileOutputStream(outputFile);
            outstream.write(contents);
            outstream.close();

Dave



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


Mime
View raw message