yes it is with SRC in WAR

and here is a class which helps you to "store"
a FormFile-Object:
(perhaps not nice, but works :-))

use:
saveFile(FormFile file, String place);


or you couldt use a properties-file (foo.properties)
which needs something like:
uploadPath=C:/path/to/nowhere

greetings

-----
package net.wessendorf.utils.file;

import java.io.ByteArrayOutputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Properties;

import org.apache.struts.upload.FormFile;

public final class UploadFile {
        
        /**
         * 
         * Private Constructor, prevents the class for beeing
         * instanced.
         * 
         *
         */
        private UploadFile() {
                
        }
        
        /**
         * 
         * Save a Jakarta FormFile to a preconfigured place.
         * 
         * @param file
         * @return
         */
        public static String saveFile(FormFile file){
                String retVal = null;
                
                try {
                //retrieve the file data
                        ByteArrayOutputStream baos = new
ByteArrayOutputStream();
                        InputStream stream = file.getInputStream();
                        Properties props = new Properties();
                        
                        //properties must exist
        
props.load(Thread.currentThread().getContextClassLoader().getResourceAsS
tream("foo.properties"));
                        String place= props.getProperty("uploadPath");

                        if(!place.endsWith("/"))
                                place = new
StringBuffer(place).insert(place.length(),"/").toString();
                        retVal = place+file.getFileName();
                        
                //write the file to the file specified
                        OutputStream bos = new FileOutputStream(retVal);
                        int bytesRead = 0;
                        byte[] buffer = file.getFileData();
                        while ((bytesRead = stream.read(buffer)) != -1)
{
                                bos.write(buffer, 0, bytesRead);
                        }
                        bos.close();
                
                //close the stream
                        stream.close();
                }
                catch (FileNotFoundException fnfe) {
                        System.out.println("Datei nicht vorhanden");
                        fnfe.printStackTrace();
                }
                catch (IOException ioe) {
                        ioe.printStackTrace();
                }
                
                        
                
                return retVal;
        }
        
        /**
         * 
         * Saves a Jakarta FormFile to a desired place.
         * 
         * @param file - the FormFile to store
         * @param place - the desired place for the file
         * @return place of file
         */
        public static String saveFile(FormFile file, String place) {
                String retVal = null;
                
                try {
                //retrieve the file data
                        ByteArrayOutputStream baos = new
ByteArrayOutputStream();
                        InputStream stream = file.getInputStream();

                        if(!place.endsWith("/"))
                                place = new
StringBuffer(place).insert(place.length(),"/").toString();

                        retVal = place+file.getFileName();
                        
                //write the file to the file specified
                        OutputStream bos = new FileOutputStream(retVal);
                        int bytesRead = 0;
                        byte[] buffer = file.getFileData();
                        while ((bytesRead = stream.read(buffer)) != -1)
{
                                bos.write(buffer, 0, bytesRead);
                        }
                        bos.close();
                
                //close the stream
                        stream.close();
                }
                catch (FileNotFoundException fnfe) {
                        System.out.println("File not found");
                        fnfe.printStackTrace();
                }
                catch (IOException ioe) {
                        ioe.printStackTrace();
                }
                
                        
                
                return retVal;
        }
}

-----Original Message-----
From: Brice Ruth [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, January 07, 2004 6:58 PM
To: Struts Users Mailing List
Subject: Re: Upload file


its in the regular (binary) distribution as well ... (with src in the 
.war, I believe)

Shishir K. Singh wrote:

>I think there are examples related to Upload in the struts src 
>distribution. Download the src and go through that. That should get you
started.
>
>Shishir
>
>-----Original Message-----
>From: Honza Spurný [mailto:[EMAIL PROTECTED]
>Sent: Wednesday, January 07, 2004 12:41 PM
>To: [EMAIL PROTECTED]
>Subject: Upload file
>
>Hello there,
>
>please could anyone help me and advise, how to upload file throught the

>form? I need to upload file from client to my computer and save it 
>somewhere. I would be pleased if this uploaded file is avaible to 
>upload into the File class...
>
>Please advise me, this is for you easy i think, but for me not. :)
>
>Thanks
>Sporak
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: [EMAIL PROTECTED]
>For additional commands, e-mail: [EMAIL PROTECTED]
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: [EMAIL PROTECTED]
>For additional commands, e-mail: [EMAIL PROTECTED]
>
>  
>

-- 
Brice D. Ruth
Sr. IT Analyst
Fiskars Brands, Inc.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to