You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Martin Cooper <ma...@tumbleweed.com> on 2003/02/11 06:28:53 UTC

RE: Apache File Upload program

First of all, you are more likely to receive a timely and helpful response
if you post your questions to the appropriate mailing list, as documented on
the FileUpload web page, rather than to individuals. I am cc'ing the
appropriate list on this reply.

For a form field, simply call FileItem.getString() to get the value of the
parameter.

For a file field, use FileItem.getFileName() to get the base name of the
uploaded file, and call FileItem.getInputStream() to access the contents.

--
Martin Cooper


> -----Original Message-----
> From: Alex.Ng@nokia.com [mailto:Alex.Ng@nokia.com]
> Sent: Thursday, February 06, 2003 8:06 PM
> To: martin.cooper@tumbleweed.com
> Subject: Apache File Upload program
> 
> 
> Hi Martin,
> 
> I am developing a web application. My web application needs 
> to allow user to upload file from
> browser to web server.  I found a good file upload Java 
> program at Apache website:
> http://jakarta.apache.org/commons/fileupload/team-list.html
> 
> I got it to work on my application. I would like to ask you 
> about retrieving a field
> value from a form. How do I get it to work ?
> 
> 	// Process the uploaded fields
>             Iterator iter = items.iterator();
>             while (iter.hasNext())
>             {
>                 FileItem item = (FileItem) iter.next();
> 
>                 if (item.isFormField())
>                 {
>                     System.out.println("Form name  -- " + 
> item.getFieldName());
> 	        System.out.println("Form value -- " + 
> req.getParameter(item.getFieldName()));	    
> 	    }
>                 else
>                 {
>                     System.out.println("File -- " + 
> item.getFieldName());
>                     System.out.println("File -- " + item.getName());
>                     item.write("d:\\temp\\upFile.txt");
>                 }
>             }
> 
> Your help is very much appreciated.
> 
> Alex
> 
> 


Re: Apache File Upload program

Posted by Schalk <sc...@volume4.co.za>.
Alex

Attached is a fileUplaod.java file that should help you in getting the job
done.

Kind Regards
Schalk Neethling
Volume4
Dedicated to an OpenSource World(tm)
Tel: +27125468436
Fax: +27125468436
email: schalk@volume4.co.za
url: www.volume4.co.za
----- Original Message -----
From: "Martin Cooper" <ma...@tumbleweed.com>
To: <Al...@nokia.com>
Cc: <co...@jakarta.apache.org>
Sent: Tuesday, February 11, 2003 7:28 AM
Subject: RE: Apache File Upload program


> First of all, you are more likely to receive a timely and helpful response
> if you post your questions to the appropriate mailing list, as documented
on
> the FileUpload web page, rather than to individuals. I am cc'ing the
> appropriate list on this reply.
>
> For a form field, simply call FileItem.getString() to get the value of the
> parameter.
>
> For a file field, use FileItem.getFileName() to get the base name of the
> uploaded file, and call FileItem.getInputStream() to access the contents.
>
> --
> Martin Cooper
>
>
> > -----Original Message-----
> > From: Alex.Ng@nokia.com [mailto:Alex.Ng@nokia.com]
> > Sent: Thursday, February 06, 2003 8:06 PM
> > To: martin.cooper@tumbleweed.com
> > Subject: Apache File Upload program
> >
> >
> > Hi Martin,
> >
> > I am developing a web application. My web application needs
> > to allow user to upload file from
> > browser to web server.  I found a good file upload Java
> > program at Apache website:
> > http://jakarta.apache.org/commons/fileupload/team-list.html
> >
> > I got it to work on my application. I would like to ask you
> > about retrieving a field
> > value from a form. How do I get it to work ?
> >
> > // Process the uploaded fields
> >             Iterator iter = items.iterator();
> >             while (iter.hasNext())
> >             {
> >                 FileItem item = (FileItem) iter.next();
> >
> >                 if (item.isFormField())
> >                 {
> >                     System.out.println("Form name  -- " +
> > item.getFieldName());
> >         System.out.println("Form value -- " +
> > req.getParameter(item.getFieldName()));
> >     }
> >                 else
> >                 {
> >                     System.out.println("File -- " +
> > item.getFieldName());
> >                     System.out.println("File -- " + item.getName());
> >                     item.write("d:\\temp\\upFile.txt");
> >                 }
> >             }
> >
> > Your help is very much appreciated.
> >
> > Alex
> >
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>