-----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  <[EMAIL PROTECTED]>
|-
| 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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to