You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@turbine.apache.org by Otto Cordero <oc...@sipecom.com> on 2003/03/12 21:16:41 UTC
Uploading files
Dear List,
I am trying to upload files with Turbine, so I have created an Action that
looks as follows:
//doPerform ...
ParameterParser params = data.getParameters();
FileItem fi = params.getFileItem("foto");
String realPath = data.getServletContext().getRealPath("/");
File file = new
File(realPath+TurbineResources.getString("services.UploadService.repository"
)
+File.separator+"fotos"+File.separator+"file.gif");
file.delete();
file.createNewFile();
FileOutputStream fos = new FileOutputStream(file);
fos.write(fi.get());
fos.flush();
However, I get a NullPointerException because the sentence fi.get() returns
null. The fact is that when I try to get anything from the FileItem, this
object returns null.
Do you know how can I solve this?
Thanks,
Otto.
---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-user-help@jakarta.apache.org
Re: Uploading files
Posted by Otto Cordero <oc...@sipecom.com>.
Thanks, I think I was forgetting the multipart statement in the HTML
Otto.
----- Original Message -----
From: "peter riegersperger" <ri...@subnet.at>
To: "Turbine Users List" <tu...@jakarta.apache.org>
Sent: Thursday, March 13, 2003 7:13 AM
Subject: Re: Uploading files
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On Wednesday 12 March 2003 21:16, Otto Cordero wrote:
> Dear List,
>
> I am trying to upload files with Turbine, so I have created an Action that
> looks as follows:
>
> //doPerform ...
> ParameterParser params = data.getParameters();
> FileItem fi = params.getFileItem("foto");
> String realPath = data.getServletContext().getRealPath("/");
> File file = new
>
File(realPath+TurbineResources.getString("services.UploadService.repository
>" )
>
> +File.separator+"fotos"+File.separator+"file.gif");
> file.delete();
> file.createNewFile();
> FileOutputStream fos = new FileOutputStream(file);
> fos.write(fi.get());
> fos.flush();
>
> However, I get a NullPointerException because the sentence fi.get()
returns
> null. The fact is that when I try to get anything from the FileItem, this
> object returns null.
>
> Do you know how can I solve this?
i didn't try your code, but this works for me:
import org.apache.turbine.services.servlet.TurbineServlet;
import org.apache.turbine.util.upload.FileItem;
import java.io.File;
[...]
FileItem fileItem = data.getParameters().getFileItem("file");
if (fileItem != null)
{
fileItem.write(TurbineServlet.getRealPath("YourPathToUploadedFiles" +
FileName));
}
additionally, make sure you've got:
<form method="post" enctype="multipart/form-data" action=[...]>
in your webpage that holds the upload form.
hope that helps,
rick
- --
|-
| peter riegersperger <ri...@subnet.at>
|-
| subnet
| platform for media art and experimental technologies
|-
| http://www.subnet.at/
|-
| muehlbacherhofweg 5 // 5020 salzburg // austria
|-
| fon/fax +43/662/842 897
|-
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.7 (GNU/Linux)
iD8DBQE+cHXyIMP39JYOy9IRAslXAKCuV9YG08A0aDs4wyTF6C0k/u971QCfcvYw
OwAP8E4Uf+NFDIteaVBateM=
=etoz
-----END PGP SIGNATURE-----
---------------------------------------------------------------------
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: Uploading files
Posted by peter riegersperger <ri...@subnet.at>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On Wednesday 12 March 2003 21:16, Otto Cordero wrote:
> Dear List,
>
> I am trying to upload files with Turbine, so I have created an Action that
> looks as follows:
>
> //doPerform ...
> ParameterParser params = data.getParameters();
> FileItem fi = params.getFileItem("foto");
> String realPath = data.getServletContext().getRealPath("/");
> File file = new
> File(realPath+TurbineResources.getString("services.UploadService.repository
>" )
>
> +File.separator+"fotos"+File.separator+"file.gif");
> file.delete();
> file.createNewFile();
> FileOutputStream fos = new FileOutputStream(file);
> fos.write(fi.get());
> fos.flush();
>
> However, I get a NullPointerException because the sentence fi.get() returns
> null. The fact is that when I try to get anything from the FileItem, this
> object returns null.
>
> Do you know how can I solve this?
i didn't try your code, but this works for me:
import org.apache.turbine.services.servlet.TurbineServlet;
import org.apache.turbine.util.upload.FileItem;
import java.io.File;
[...]
FileItem fileItem = data.getParameters().getFileItem("file");
if (fileItem != null)
{
fileItem.write(TurbineServlet.getRealPath("YourPathToUploadedFiles" +
FileName));
}
additionally, make sure you've got:
<form method="post" enctype="multipart/form-data" action=[...]>
in your webpage that holds the upload form.
hope that helps,
rick
- --
|-
| peter riegersperger <ri...@subnet.at>
|-
| subnet
| platform for media art and experimental technologies
|-
| http://www.subnet.at/
|-
| muehlbacherhofweg 5 // 5020 salzburg // austria
|-
| fon/fax +43/662/842 897
|-
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.7 (GNU/Linux)
iD8DBQE+cHXyIMP39JYOy9IRAslXAKCuV9YG08A0aDs4wyTF6C0k/u971QCfcvYw
OwAP8E4Uf+NFDIteaVBateM=
=etoz
-----END PGP SIGNATURE-----
---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-user-help@jakarta.apache.org