You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@turbine.apache.org by jiatj <ji...@neusoft.com> on 2002/02/15 16:40:11 UTC

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:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: FileItem storeLocation

Posted by John McNally <jm...@collab.net>.
The file is already written to the temporary location by the time you
have a FileItem, so it is too late to change it there.  You need to
specify the path to FileUpload class, either with the setter or in the
parseRequest method.  As it appears you are using this integrated into
ParameterParser, you would set it in TurbineResources.properties

#
# The directory where files will be temporarily stored.
#
services.UploadService.repository=/tmp

Note that the directory must exist.  The service first checks that the
directory exists in the webapp directory, if not it assumes the path was
absolute.

john mcnally


Bruce Altner wrote:
> 
> Greetings:
> 
> My application uses FileItem in a class which uploads a file from the
> user's local drive to a remote server. It has always worked without a hitch
> but recently was deployed on a box where the default storeLocation is
> write-protected, so it fails. I am interested in being able to specify the
> location where the tmp file is written to avoid this problem but
> storeLocation  is a protected field in FileItem and there is no accessor
> method (that I could find). Do I have to write my own version of FileItem
> or is there a way to set this using this class.
> 
> Here is how I am using FileItem:
> 
>          FileItem fi = data.getParameters().getFileItem( "filename" );
>          InputStream ins = fi.getInputStream();
>          String fqFilename = fi.getFileName();
> 
> etc.
> 
> Thanks,
> Bruce
> 
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>

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


FileItem storeLocation

Posted by Bruce Altner <ba...@hq.nasa.gov>.
Greetings:

My application uses FileItem in a class which uploads a file from the 
user's local drive to a remote server. It has always worked without a hitch 
but recently was deployed on a box where the default storeLocation is 
write-protected, so it fails. I am interested in being able to specify the 
location where the tmp file is written to avoid this problem but 
storeLocation  is a protected field in FileItem and there is no accessor 
method (that I could find). Do I have to write my own version of FileItem 
or is there a way to set this using this class.

Here is how I am using FileItem:


         FileItem fi = data.getParameters().getFileItem( "filename" );
         InputStream ins = fi.getInputStream();
         String fqFilename = fi.getFileName();

etc.

Thanks,
Bruce




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


RE: Help on UploadService

Posted by Will Glass-Husain <wg...@forio.com>.
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:jiatj@neusoft.com]
Sent: Friday, February 15, 2002 7:40 AM
To: turbine-user@jakarta.apache.org
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:
<ma...@jakarta.apache.org>
For additional commands, e-mail:
<ma...@jakarta.apache.org>


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