You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@turbine.apache.org by "August, Terry" <Te...@Honeywell.com> on 2001/03/08 17:07:21 UTC
File Upload
I am having a problem using the Upload Service. I have set the following
parameter in my TurbineResources.properties file:
services.TurbineUploadService.automatic=true
It seems that when using a Velocity screen to upload a file, it sometimes
gets uploaded to the temporary upload directory but not always. I am thus
somewhat confused. Could someone please post sample code for the Velocity
upload form screen, and a corresponding java file that actually saves the
file out of the temporary upload directory.
Here is the code that I am using: Note that I am not doing anything
significant in the doPerform method because the file is not being uploaded
at all.
Upload.vm:
<form enctype="multipart/form-data" method="POST">
<input type="hidden" name="action" value="UploadFile" />
<input type="file" name="filename">
<input type="submit" value="upload" />
UploadFile.java:
import org.apache.velocity.context.Context;
import org.apache.turbine.util.RunData;
import org.apache.turbine.modules.actions.VelocityAction;
public class UploadFile extends VelocityAction
{
public void doPerform(RunData data, Context context) throws Exception
{
System.out.println("uploaded");
}
}
Thank your for your help.
T
---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-user-help@jakarta.apache.org
Re: File Upload
Posted by Hervé Guidetti <he...@idbsoft.ch>.
Hi,
Is that happend with little file ?? If yes, try to set the
services.TurbineUploadService.size.threshold=0
This forces all files to be grab on the temporary directory
HTH,
Hervé
----- Original Message -----
From: August, Terry <Te...@Honeywell.com>
To: <tu...@jakarta.apache.org>
Sent: Thursday, March 08, 2001 5:07 PM
Subject: File Upload
>
> I am having a problem using the Upload Service. I have set the following
> parameter in my TurbineResources.properties file:
>
> services.TurbineUploadService.automatic=true
>
> It seems that when using a Velocity screen to upload a file, it sometimes
> gets uploaded to the temporary upload directory but not always. I am thus
> somewhat confused. Could someone please post sample code for the Velocity
> upload form screen, and a corresponding java file that actually saves the
> file out of the temporary upload directory.
>
> Here is the code that I am using: Note that I am not doing anything
> significant in the doPerform method because the file is not being uploaded
> at all.
>
> Upload.vm:
>
> <form enctype="multipart/form-data" method="POST">
> <input type="hidden" name="action" value="UploadFile" />
> <input type="file" name="filename">
> <input type="submit" value="upload" />
>
> UploadFile.java:
>
> import org.apache.velocity.context.Context;
> import org.apache.turbine.util.RunData;
> import org.apache.turbine.modules.actions.VelocityAction;
>
> public class UploadFile extends VelocityAction
> {
> public void doPerform(RunData data, Context context) throws Exception
> {
> System.out.println("uploaded");
> }
> }
>
> Thank your for your help.
>
> T
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: turbine-user-help@jakarta.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-user-help@jakarta.apache.org
Re: File Upload
Posted by Oskar <os...@2n.pl>.
Hi,
As I can see, your upload form is OK.
You should process this request, in your UploadFile Action, get
th FileItem from ParameterParser and store the file wherever you want:
import org.apache.turbine.util.upload.FileItem;
public void doPerform(RunData data, Context context) throws Exception
{
// get the FileItem
FileItem ff = data.getParameters().getFileItem("filename");
// open stream and save file
FileOutputStream os = new FileOutputStream("some_file_name_with_path");
os.write(ff.get());
os.close();
}
Look at FileItem class for more...
NOTE: There is another problem - in tdk1.1a10 it works very good, but I have
problems with tdk1.1a11, because "getFileItem" returns null constantly - I
don't know why....
Regards
Oskar
---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-user-help@jakarta.apache.org
Re: File Upload
Posted by Jason van Zyl <jv...@periapt.com>.
"August, Terry" wrote:
> I am having a problem using the Upload Service. I have set the following
> parameter in my TurbineResources.properties file:
> services.TurbineUploadService.automatic=true
>
> It seems that when using a Velocity screen to upload a file, it sometimes
> gets uploaded to the temporary upload directory but not always. I am thus
> somewhat confused. Could someone please post sample code for the Velocity
> upload form screen, and a corresponding java file that actually saves the
> file out of the temporary upload directory.
This is an excerpt from the TR.props file.
#
# The maximum size of a request that will have it's elements cached in
# memory by TurbineUploadService class.
#
services.TurbineUploadService.size.threshold=0
Set the above property to zero so that your temporary files
will always be written to disk if that is what you desire :-)
Everything else looks fine, just change that one property
and try it again.
--
jvz.
Jason van Zyl
jvanzyl@periapt.com
http://jakarta.apache.org/velocity
http://jakarta.apache.org/turbine
---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-user-help@jakarta.apache.org
Re: File Upload
Posted by Jon Stevens <jo...@latchkey.com>.
on 3/8/01 8:07 AM, "August, Terry" <Te...@Honeywell.com> wrote:
> It seems that when using a Velocity screen to upload a file, it sometimes
> gets uploaded to the temporary upload directory but not always. I am thus
> somewhat confused.
Depends on the size of the file. If you go through the UploadService source
you can find the property that defines this.
-jon
--
If you come from a Perl or PHP background, JSP is a way to take
your pain to new levels. --Anonymous
<http://jakarta.apache.org/velocity/ymtd/ymtd.html>
---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-user-help@jakarta.apache.org