You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@turbine.apache.org by Patrice Le Cozler <pl...@dexem.com> on 2002/04/03 16:33:42 UTC

upload a file from a form

Hello,

I need to upload a XML file from a form and parse it to put the datas it
contains in a database.

So I wrote my form like this :

|   <form method="post" ENCTYPE="multipart/form-data"
action="$link.setPage("Index.vm").setAction("SQL")">
|       upload :
|         <input type=file name="upfile">
|         <input type="submit" name="eventSubmit_doUpload"
value="Upload">
|   </form>

...and the corresponding SQL.java like that :

|        public void doUpload(RunData data, Context context)
|     throws Exception
|     {
|      Log.debug("Upload : "+data.getParameters().getString("upfile"));
|     }

( the Log.debug method just allows me to verify that the doUpload method
is called when I press the "Upload" button of the form )

but all I get in my log file is :

Upload :

so where's the file name ?

thanks

Patrice

Re: upload a file from a form

Posted by Bartek Walter <Ba...@man.poznan.pl>.
Patrice Le Cozler wrote:
> 
> Hello,
> 
> I need to upload a XML file from a form and parse it to put the datas it
> contains in a database.
> 
> So I wrote my form like this :
> 
> |   <form method="post" ENCTYPE="multipart/form-data"
> action="$link.setPage("Index.vm").setAction("SQL")">
> |       upload :
> |         <input type=file name="upfile">
> |         <input type="submit" name="eventSubmit_doUpload"
> value="Upload">
> |   </form>
> 
> ...and the corresponding SQL.java like that :
> 
> |        public void doUpload(RunData data, Context context)
> |     throws Exception
> |     {
> |      Log.debug("Upload : "+data.getParameters().getString("upfile"));
> |     }
> 
> ( the Log.debug method just allows me to verify that the doUpload method
> is called when I press the "Upload" button of the form )
> 
> but all I get in my log file is :
> 
> Upload :
> 

Fulcrum (and T2.1) comes with its own multipart-form parser.

Use something like (AFAIR):
data.getParameters().getFileItem("upfile").getFileName()

Look also ar o.a.f.services.upload.FileItem interface.

> so where's the file name ?
> 
> thanks
> 
> Patrice

Bartek Walter

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: upload a file from a form

Posted by Daniel Rall <dl...@finemaltcoding.com>.
"Matthew Inger" <ma...@sedonacorp.com> writes:

> You need to parse the data different.  Servlet API does
> not parse multipart/form-data.  I would reccommend o'reilly's
> org.oreilly.servlet package.  go to www.oreilly.org for more
> information.  It's a java package written by Jason Hunter
> (who also wrote the O'Reilly Java Servlet book).  You MUST
> buy the book to legally use the classes.

The Servlet API does not automatically parse file uploads, but Turbine
can.  See the UploadService.

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: upload a file from a form

Posted by Matthew Inger <ma...@sedonacorp.com>.
You need to parse the data different.  Servlet API does
not parse multipart/form-data.  I would reccommend o'reilly's
org.oreilly.servlet package.  go to www.oreilly.org for more
information.  It's a java package written by Jason Hunter
(who also wrote the O'Reilly Java Servlet book).  You MUST
buy the book to legally use the classes.

-----Original Message-----
From: plecozler@mailhub7.isdnet.net
[mailto:plecozler@mailhub7.isdnet.net]On Behalf Of Patrice Le Cozler
Sent: Wednesday, April 03, 2002 9:34 AM
To: turbine-user@jakarta.apache.org
Subject: upload a file from a form


Hello,

I need to upload a XML file from a form and parse it to put the datas it
contains in a database.

So I wrote my form like this :

|   <form method="post" ENCTYPE="multipart/form-data"
action="$link.setPage("Index.vm").setAction("SQL")">
|       upload :
|         <input type=file name="upfile">
|         <input type="submit" name="eventSubmit_doUpload"
value="Upload">
|   </form>

...and the corresponding SQL.java like that :

|        public void doUpload(RunData data, Context context)
|     throws Exception
|     {
|      Log.debug("Upload : "+data.getParameters().getString("upfile"));
|     }

( the Log.debug method just allows me to verify that the doUpload method
is called when I press the "Upload" button of the form )

but all I get in my log file is :

Upload :

so where's the file name ?

thanks

Patrice


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>