I'm not clear on whether you're asking about the path to the file the
user selected for upload, or about the location of the file after it
has been uploaded.

In the first case, whether or not you get the full path to the file
the user selected is up to the browser. Most browsers provide only the
base file name, and not the full path. This is primarily for security
reasons - it's not a good idea to expose the user's local file system
to the server. Some browsers do, however, provide the full path.

In the second case, you simply need to decide for yourself where you
want the file to be written, and then pass that to the
FileItem.write() method. You don't want to do what you have in the
code you provide, since that just takes whatever the browser provided
for the file name. If that provides a path, then it could try to write
anywhere on the server and you are not checking where that might be.
If it doesn't provide a path, then it's going to be written in
whatever the web container deems to be the current working directory,
which is also probably not what you want.

--
Martin Cooper


On Mon, 27 Sep 2004 12:11:57 +0200, Omar Adobati <[EMAIL PROTECTED]> wrote:
> This is the code I've write to perform a fileupload.
> It's seems to work nice but there is a definitive problem... I don't know, and can't 
> understand, how i can specify the destination path to the file I need to upload.
> I'm using commons fileUpload package...
> 
> Does anybody can help me?
> 
> Tanks in advice,
>  Omar (from Italy)
> 
> ---
> 
> boolean isMultipart = FileUpload.isMultipartContent(request);
>  if(isMultipart){
>    DiskFileUpload upload = new DiskFileUpload();
> 
>    List item = upload.parseRequest(request);
>    Iterator iter  = item.iterator();
>    while(iter.hasNext()){
>      DefaultFileItem fitem = (DefaultFileItem)iter.next();
>      if(fitem.isFormField()){
>        out.println(fitem.getFieldName());
>        out.println(fitem.getName());
>        out.println(fitem.getSize());
>        out.println(fitem.getString());
>      }
>      if(!fitem.isFormField()){
>        out.println(fitem.getFieldName() + "<br>");
>        out.println(fitem.getName() + "<br>");
>        out.println(fitem.getSize() + "<br>");
>        out.println(fitem.getContentType() + "<br>");
>        out.println(fitem.isInMemory() + "<br>");
>        File uploadFile = new File(fitem.getName());
>        fitem.write(uploadFile);
>      }
>    }
>  }
>

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

Reply via email to