Hi Reimon,

I just implemented this for the first time, and discovered (the hard way)
each of the following potential pitfalls with upload.   I suspect one of
these might be your mistake.

(1)  Your form enctype must be set to multipart/form-data, i.e.
 <form name="form1" method="post" action="$link.setAction('UploadFiles')"
enctype="multipart/form-data">

(2) Check the Upload properties of the Turbine.resources file.

services.UploadService.automatic=true     (must be true)
services.UploadService.repository=/temp   (must be valid directory in your
webapp)
services.UploadService.size.max=3145728   (must be big enough for your
files)

I suspect the last point might be Christian's problem in his recent post.

(3) In Turbine 2.1, FileItem.write has a bug.  All files saved are zero
length files (it doesn't close the outputstream).  Various posts on the
mailing list recommend using the latest version from CVS (currently 2.2b).
Tried this, it's a pain as there are incompatibilities elsewhere between 2.1
and 2.2.  Instead, I went back to 2.1, but then included the new
FileItem.write routine from 2.2b in my code.

http://cvs.apache.org/viewcvs/jakarta-turbine-2/src/java/org/apache/turbine/
util/upload/FileItem.java

http://cvs.apache.org/viewcvs/jakarta-turbine-2/src/java/org/apache/turbine/
util/upload/FileItem.java?rev=1.3&content-type=text/vnd.viewcvs-markup

If you do a diff with the latest FileItem (1.3) and the earlier version
(1.2) you can see the only difference is FileItem.Write.

Then my code reads:

        ParameterParser pp = data.getParameters();
        FileItem TheFile = pp.getFileItem("FileName");
        if (theFile != null) {
                try {
                        FilePath = "savefile.test";

                        write(FilePath,TheFile);    // calls my custom write, based on
FileItem.write

                } catch (IOException E) {
                        Log.error("Can't upload file.  Exception: " + E);
                }

        }

Once I got to this point, everything worked great!  Hope this saves you a
few hours of messing around like I did.

Best, WILL



-----Original Message-----
From: jiatj [mailto:[EMAIL PROTECTED]]
Sent: Friday, February 15, 2002 7:40 AM
To: [EMAIL PROTECTED]
Subject: Help on UploadService


I tried to use turbine's upload service, however, I got a mistake,


...

ParameterParser params = new DefaultParameterParser();
params.setRequest(request);

FileItem fileItem = params.getFileItem("filename");

sorry, the fileItem is null.

I had looked into TurbineUploadService, it's method parserRequest(request,
params,path), maybe I am not farmilar with the RFC, I think maybe here I got
wrong, because the first while condition is false!

I hurry to make it out, please send me some suggestions,thank you!

Reimon.J


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


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

Reply via email to